Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misaligned character/byte when throwing an error #351

Open
Timeroot opened this issue Nov 18, 2022 · 0 comments
Open

Misaligned character/byte when throwing an error #351

Timeroot opened this issue Nov 18, 2022 · 0 comments
Labels

Comments

@Timeroot
Copy link

The following misformed JSON (missing a comma between fields) is supposed to give an error like this:

>> JSON.parse("{\"a\":\"foob\"      \"b\":5}")
Expected ',' here
Line: 0
Around: ...{"a":"foob"      "b":5}...
                            ^
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:33
 [2] _error(message::String, ps::JSON.Parser.MemoryParserState)
   @ JSON.Parser C:\Users\AlexanderMeiburg\.julia\packages\JSON\NeJ9k\src\Parser.jl:140
 [3] _error_expected_char(c::UInt8, ps::JSON.Parser.MemoryParserState)
   @ JSON.Parser C:\Users\AlexanderMeiburg\.julia\packages\JSON\NeJ9k\src\Parser.jl:83

But with the right multibyte UTF-8 characters in the right places, it throws an error while trying to throw the error:

>> JSON.parse("{\"a\":\"0⊆⊆0\"      \"b\":5}")
StringIndexError: invalid index [13], valid nearby indices [11]=>'⊆', [14]=>'0'

Stacktrace:
 [1] string_index_err(s::String, i::Int64)
   @ Base .\strings\string.jl:12
 [2] getindex
   @ .\strings\string.jl:262 [inlined]
 [3] _error(message::String, ps::JSON.Parser.MemoryParserState)
   @ JSON.Parser C:\Users\AlexanderMeiburg\.julia\packages\JSON\NeJ9k\src\Parser.jl:140
 [4] _error_expected_char(c::UInt8, ps::JSON.Parser.MemoryParserState)
   @ JSON.Parser C:\Users\AlexanderMeiburg\.julia\packages\JSON\NeJ9k\src\Parser.jl:83

It's not very critical because it's just JSON.jl failing to handle bad JSON gracefully. But, when parsing very large JSON and trying to see what the error is, this becomes pretty frustrating because it just gives a byte-offset into the file that I need to scan to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants