Bug 158033 - Web Inspector: JSON Parse error message should include more useful details about what caused parsing to fail
Summary: Web Inspector: JSON Parse error message should include more useful details ab...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-05-24 11:43 PDT by Brian Burg
Modified: 2016-10-05 10:24 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Burg 2016-05-24 11:43:33 PDT
Currently, an SyntaxError is thrown, but the line and column properties are set to the call site of JSON.parse().
What I really want to know is the string that failed to parse, and where within string parsing failed (approximately).
If the parse error says 'invalid number', I would expect to be able to figure out where it died.
This is kind of difficult since the argument to JSON.parse is generally not a resource we already have in a text editor, so we'd need to figure out how to display that text (which could be megabytes of JSON).
Comment 1 Brian Burg 2016-05-27 07:18:03 PDT
Ping for import.
Comment 2 Radar WebKit Bug Importer 2016-05-27 07:20:50 PDT
<rdar://problem/26516676>
Comment 3 JF Bastien 2016-10-04 16:24:04 PDT
This is pretty bad:
  jsc -e 'JSON.parse("{\"a\": {},}")'
  Exception: SyntaxError: JSON Parse error: Property name must be a string literal
  at [Command Line]:1
  parse@[native code]
  global code@[Command Line]:1:11

Looks like it comes from JSC:
  Source/JavaScriptCore/runtime/LiteralParser.cpp:                    m_parseErrorMessage = ASCIILiteral("Property name must be a string literal");

There are some tests for it:
  LayoutTests/js/dom/JSON-parse-expected.txt:PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal.
  LayoutTests/js/dom/JSON-parse-expected.txt:PASS tests[i](nativeJSON) threw exception SyntaxError: JSON Parse error: Property name must be a string literal.

I may un-lazy and try to improve it at some point...