Skip to content

Commit

Permalink
Add error handling for loadPlugins
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 26, 2023
1 parent aa45fc8 commit 6c94962
Showing 1 changed file with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ export const Hg38Exome = () => {
return <JBrowseLinearGenomeView viewState={state} />
}
export const WithExternalPlugins = () => {
const [error, setError] = useState<unknown>()
// usage with buildtime plugins
// this plugins array is then passed to the createViewState constructor
//
Expand All @@ -610,20 +611,20 @@ export const WithExternalPlugins = () => {
useEffect(() => {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
;(async () => {
const loadedPlugins = await loadPlugins([
{
name: 'UCSC',
url: 'https://unpkg.com/jbrowse-plugin-ucsc@^1/dist/jbrowse-plugin-ucsc.umd.production.min.js',
},
])
setPlugins(loadedPlugins)
try {
const loadedPlugins = await loadPlugins([
{
name: 'UCSC',
url: 'https://unpkg.com/jbrowse-plugin-ucsc@^1/dist/jbrowse-plugin-ucsc.umd.production.min.js',
},
])
setPlugins(loadedPlugins)
} catch (e) {
setError(e)
}
})()
}, [setPlugins])

if (!plugins) {
return null
}

const state = createViewState({
assembly: {
name: 'hg19',
Expand Down Expand Up @@ -657,7 +658,7 @@ export const WithExternalPlugins = () => {
},
},
},
plugins: plugins.map(p => p.plugin),
plugins: plugins?.map(p => p.plugin),
tracks: [
{
type: 'FeatureTrack',
Expand Down Expand Up @@ -711,7 +712,13 @@ export const WithExternalPlugins = () => {
},
},
})
return <JBrowseLinearGenomeView viewState={state} />
return error ? (
<div style={{ color: 'red' }}>{`${error}`}</div>
) : !plugins ? (
<div>Loading plugins...</div>
) : (
<JBrowseLinearGenomeView viewState={state} />
)
}

export const WithInternetAccounts = () => {
Expand Down

0 comments on commit 6c94962

Please sign in to comment.