Skip to content

Commit 6d3729f

Browse files
authored
Merge pull request #26 from magjac/fail-fast
Try to parse DOT and don't attempt to render if parsing fails
2 parents b3bbc31 + 28b4f2b commit 6d3729f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Graph.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ class Graph extends React.Component {
111111
this.prevFit = this.props.fit;
112112
}
113113
this.prevDotSrc = this.props.dotSrc;
114+
try {
115+
this.prelDotGraph = new DotGraph(this.props.dotSrc);
116+
}
117+
catch(error) {
118+
let {location: {start: {line}}, message} = error;
119+
this.props.onError({message: message, line: line});
120+
return;
121+
}
114122
this.rendering = true;
115123
this.graphviz
116124
.width(width)
@@ -129,13 +137,7 @@ class Graph extends React.Component {
129137
handleRenderGraphReady() {
130138
this.svg = this.div.selectWithoutDataPropagation("svg");
131139
this.graph0 = this.svg.selectWithoutDataPropagation("g");
132-
try {
133-
this.dotGraph = new DotGraph(this.props.dotSrc);
134-
}
135-
catch(error) {
136-
let {location: {start: {line}}, message} = error;
137-
this.props.onError({message: message, line: line});
138-
}
140+
this.dotGraph = this.prelDotGraph;
139141
this.addEventHandlers();
140142
this.rendering = false;
141143
if (!this.renderGraphReady) {

0 commit comments

Comments
 (0)