diff --git a/src/components/App.tsx b/src/components/App.tsx index 08d6784..8c684fd 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -37,7 +37,7 @@ class App extends React.Component { this.setState({ source: source, explain: explain, problem: "" }); } catch (e) { - this.setState({ source: this.state.source, explain: null, problem: e }); + this.setState({ source: this.state.source, explain: null, problem: e.message }); } } diff --git a/src/utils/GoFlow.test.tsx b/src/utils/GoFlow.test.tsx new file mode 100644 index 0000000..bc59e58 --- /dev/null +++ b/src/utils/GoFlow.test.tsx @@ -0,0 +1,9 @@ +import { ReadSession } from './GoFlow'; + +it('loads session from JSON', () => { + // loads when top-level object is session + expect(ReadSession('{"status": "complete", "runs": []}')).toMatchObject({ status: "complete", runs: [] }); + + // loads when session is nested object + expect(ReadSession('{"session": {"status": "complete", "runs": []}}')).toMatchObject({ status: "complete", runs: [] }); +}) \ No newline at end of file diff --git a/src/utils/GoFlow.tsx b/src/utils/GoFlow.tsx index d3f1d4d..691ecd3 100644 --- a/src/utils/GoFlow.tsx +++ b/src/utils/GoFlow.tsx @@ -49,6 +49,11 @@ export function ReadSession(src: string): Session { throw new Error(`invalid JSON: ${e}`); } + // could be an output from simulator which has nested session + if (typeof obj.session === "object") { + obj = obj.session + } + if (!isSession(obj)) { throw new Error("not a valid session object") }