Skip to content

Commit

Permalink
Better ontology loading error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens committed Nov 6, 2024
1 parent 203b778 commit 93a9011
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
UriLocation,
isUriLocation,
} from '@jbrowse/core/util'
import { IDBPTransaction, IndexNames, StoreNames } from 'idb/with-async-ittr'
import {
deleteDB,
IDBPTransaction,
IndexNames,
StoreNames,
} from 'idb/with-async-ittr'

import { textSearch } from './fulltext'
import { OntologyDB, OntologyDBEdge, isDeprecated } from './indexeddb-schema'
Expand Down Expand Up @@ -176,18 +181,24 @@ export default class OntologyStore {
return db
}

const { sourceLocation, sourceType } = this
if (sourceType === 'obo-graph-json') {
await this.loadOboGraphJson(db)
} else {
throw new Error(
`ontology source file ${JSON.stringify(
sourceLocation,
)} has type ${sourceType}, which is not yet supported`,
)
}
try {
const { sourceLocation, sourceType } = this
if (sourceType === 'obo-graph-json') {
await this.loadOboGraphJson(db)
} else {
throw new Error(

Check warning on line 189 in packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts#L188-L189

Added lines #L188 - L189 were not covered by tests
`ontology source file ${JSON.stringify(
sourceLocation,
)} has type ${sourceType}, which is not yet supported`,
)
}

return db
return db
} catch (error) {
db.close()
await deleteDB(this.dbName)
throw error

Check warning on line 200 in packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/index.ts#L198-L200

Added lines #L198 - L200 were not covered by tests
}
}

async termCount(tx?: Transaction<['nodes']>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,14 @@ export async function loadOboGraphJson(this: OntologyStore, db: Database) {
// TODO: using file streaming along with an event-based json parser
// instead of JSON.parse and .readFile could probably make this faster
// and less memory intensive
const oboGraph = JSON.parse(
await openLocation(this.sourceLocation).readFile('utf8'),
) as GraphDocument
let oboGraph: GraphDocument
try {
oboGraph = JSON.parse(
await openLocation(this.sourceLocation).readFile('utf8'),
) as GraphDocument
} catch {
throw new Error('Error in loading ontology')

Check warning on line 93 in packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/indexeddb-storage.ts

View check run for this annotation

Codecov / codecov/patch

packages/jbrowse-plugin-apollo/src/OntologyManager/OntologyStore/indexeddb-storage.ts#L93

Added line #L93 was not covered by tests
}

const parseTime = Date.now()

Expand Down

0 comments on commit 93a9011

Please sign in to comment.