Parse method does not return a boolean
See original GitHub issueDescribe the bug
The mermaid.parse()
method is supposed to return a boolean when passed a string of mermaid markdown, but it is instead returning undefined
for valid markup, and an Uncaught
error on invalid markup.
To Reproduce
mermaid.parse('graph TD\n')
= returns undefined
mermaid.parse('graph TD\n{')
= returns Uncaught {str: "Parse error on line 1...
Expected behavior Per this section of the current documentation,
“The function mermaid.parse(txt) takes a text string as an argument and returns true if the text is syntactically correct and false if it is not.”
mermaid.parse('graph TD\n')
= should return true
mermaid.parse('graph TD\n{')
= should return false
Screenshots
Desktop (please complete the following information):
- OS: Windows 10 Pro
- Browser: Chrome
- Version: 77.0.3865.120
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Parse to Boolean or check String Value
The try parse function will try to convert the value of the string to boolean, if it can not return the value of...
Read more >C# | Boolean.Parse() Method
Return Value: This method returns true if value is equivalent to TrueString false if value is equivalent to FalseString.
Read more >Java.lang.Boolean.parseBoolean() Method
The java.lang.Boolean.parseBoolean(String s) parses the string argument as a boolean. The boolean returned represents the value true if the string argument is ......
Read more >Boolean.TryParse Method (System)
A span containing the characters representing the value to convert. ... When this method returns, if the conversion succeeded, contains true if value...
Read more >Parse vs TryParse in .Net - Mendel Bakaleynik - Medium
Parse() returns the translated value or an error. · TryParse will never return an error. · TryParse returns 2 things. 1) A boolean...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re right, I also consider that to be a flaw in the docs. I like the idea of a separate method, that could be handy. Will implement that.
Still the
parse
function would throw an exception (because removing that would be a breaking change). Regarding execution flow, it would stop if you don’t catch the exception. And if you catch it, you automatically know that the parser failed. Imo that’s a suitable solution that would also fit the code you posted (if you change it a bit).