3 ms·
Reporting the last valid input and the start of the first invalid location (possibly repeating the first couple characters of invalid content, filtered for safe
by mjevans 7y ago
Reporting the last valid input and the start of the first invalid location (possibly repeating the first couple characters of invalid content, filtered for safety) is what I'd generally prefer in an error message.
- evilpie 7y agoFor some reason the author truncated the error messages reported by Chrome and Firefox to not include the line/column. The message in Firefox is: JSON.parse: expected ',' or ']' after array element at line 1 column 3 of the JSON data In Chrome: Unexpected number in JSON at position 2
- s_gourichon 7y agoShowing the boundary between accepted and rejected input is indeed a good idea. The case discussed in the article would benefit of a display with spaces between tokens. Example: Source: [01] Compiler error: [ 0 1 ] ----^ SyntaxError: JSON.parse: expected ‘,’ or ‘]’ after array element Such situation of two tokens without a separator character becomes much more obvious. Notice also the character showing point of error. OCaml has been doing for a while ( https://ocaml.org/learn/tutorials/common_error_messages.html https://ocaml.org/learn/tutorials/common_error_messages.html now shows underlined parts) then clang, cf. https://clang.llvm.org/diagnostics.html https://clang.llvm.org/diagnostics.html . This is much quicker for the human to communicate, than "line x column y".