question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Parse method does not return a boolean

See original GitHub issue

Describe 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 image

Desktop (please complete the following information):

  • OS: Windows 10 Pro
  • Browser: Chrome
  • Version: 77.0.3865.120

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
klemmchrcommented, Nov 14, 2019

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.

1reaction
klemmchrcommented, Nov 13, 2019

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found