diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-26 13:13:12 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-26 14:36:30 +0200 |
commit | 0f2b3cd2801d1b1c04675eb30e0343705cf36351 (patch) | |
tree | 1686314f128476d28dcee12548b021c55b1be6f3 | |
parent | 015d65bc6f1615c96de766f8e660532fc92d2459 (diff) | |
download | serenity-0f2b3cd2801d1b1c04675eb30e0343705cf36351.zip |
Browser: Show a "source location hint" for syntax errors :^)
-rw-r--r-- | Applications/Browser/ConsoleWidget.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Applications/Browser/ConsoleWidget.cpp b/Applications/Browser/ConsoleWidget.cpp index 6d1852ffdb..9737b744bc 100644 --- a/Applications/Browser/ConsoleWidget.cpp +++ b/Applications/Browser/ConsoleWidget.cpp @@ -79,15 +79,18 @@ ConsoleWidget::ConsoleWidget() auto parser = JS::Parser(JS::Lexer(js_source)); auto program = parser.parse_program(); + StringBuilder output_html; if (parser.has_errors()) { auto error = parser.errors()[0]; + auto hint = error.source_location_hint(js_source); + if (!hint.is_empty()) + output_html.append(String::format("<pre>%s</pre>", hint.characters())); m_interpreter->throw_exception<JS::SyntaxError>(error.to_string()); } else { m_interpreter->run(*program); } if (m_interpreter->exception()) { - StringBuilder output_html; output_html.append("Uncaught exception: "); output_html.append(JS::MarkupGenerator::html_from_value(m_interpreter->exception()->value())); print_html(output_html.string_view()); |