Skip to content

Commit

Permalink
Extract error message/stack (#1619)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored Aug 20, 2023
1 parent f0fd797 commit 66a0bc3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion mermaid/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ export class Worker {
const { svg } = await window.mermaid.render('container', definition)
return { svg, error: null }
} catch (err) {
return { svg: null, error: err }
return {
svg: null,
error: {
name: 'name' in err && err.name,
message: 'message' in err && err.message,
stack: 'stack' in err && err.stack
}
}
}
}, task.source, mermaidConfig)
successfulSpan(span)
Expand Down
2 changes: 1 addition & 1 deletion mermaid/test/convert-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('#convert', function () {
await new Worker(browser).convert(new Task('not a valid mermaid code', testCase.isPng))
expect.fail('Should throw a SyntaxError exception')
} catch (err) {
expect(err.message).to.equal('Syntax error in graph: {"name":"UnknownDiagramError"}')
expect(err.message).to.be.a('string').and.satisfy(msg => msg.startsWith('Syntax error in graph: {"name":"UnknownDiagramError"'), 'Error message should starts with \'Syntax error in graph: {"name":"UnknownDiagramError\'')
} finally {
await browser.close()
}
Expand Down

0 comments on commit 66a0bc3

Please sign in to comment.