Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenClontz committed Nov 4, 2024
1 parent cc26f09 commit ea9fa67
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/viewer/src/components/GraphViz/GraphViz.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,22 @@
import * as graphviz from 'd3-graphviz'
export let dot = 'digraph {a -> b}'
let graphDiv: HTMLElement
onMount(() => {
d3.select(graphDiv).graphviz().renderDot(dot)
})
const renderer = (dot: string) => {
return () => {
try {
d3.select(graphDiv).graphviz().renderDot(dot)
} catch {
d3.select(graphDiv)
.graphviz()
.renderDot(
`digraph {A[label="Invalid dot code",color=red,fontcolor=red]}`,
)
}
}
}
onMount(renderer(dot))
$: if (graphDiv) {
d3.select(graphDiv).graphviz().renderDot(dot)
renderer(dot)()
}
</script>

Expand Down

0 comments on commit ea9fa67

Please sign in to comment.