Misleading error parsing Unicode characters in EDN #166

Open
opened 2020-08-06 16:56:02 +00:00 by gburd · 0 comments
gburd commented 2020-08-06 16:56:02 +00:00 (Migrated from github.com)

I'm not sure exactly what the best way to surface this is, but following the error messages led me down a long path. The messages make it appear that the particular character is the problem, when in reality it was a quote that was opened and never closed in a previous operation . For example:

conn.transact(&mut sqlite, r#"[
        {:db/id 17592186049155, :artist/name "W}
        {:db/id 17592186049242, :artist/name "ö"}
]"#).unwrap();

Leads to an error pointing to the ö character, which led me down a path of removing each 'invalid' character, one by one:

thread 'test_big' panicked at 'called `Result::unwrap()` on an `Err` value: Error(EdnParseError(ParseError { line: 3, column: 47, offset: 97, expected: {"[12]", "\t", "nil", "[0-9]", "\r", "[", "0x", "#f", "[*!_?$%&=<>]", "\"", "true", "{", ";", ".", ",", "+", "...", "[2-9]", "}", "(", "\n", "[a-z]", "-", " ", ":", "[A-Z]", "#{", "0", "false", "[3]"} }), State { next_error: None, backtrace: None })', src/libcore/result.rs:859
note: Run with `RUST_BACKTRACE=1` for a backtrace.

If you finally get to the last instance, i.e.

conn.transact(&mut sqlite, r#"[
        {:db/id 17592186049155, :artist/name "W}
        {:db/id 17592186049242, :artist/name "o"}
]"#).unwrap();

Then we end up with an error pointing to the final bracket:

thread 'test_big' panicked at 'called `Result::unwrap()` on an `Err` value: Error(EdnParseError(ParseError { line: 4, column: 6, offset: 106, expected: {"\\tab", "\"", "\\\"", "[^\"]"} }), State { next_error: None, backtrace: None })', src/libcore/result.rs:859
note: Run with `RUST_BACKTRACE=1` for a backtrace.

If there was some kind of context in the error message pointing to the origin of the opened string it would save a ton of time.

I'm not sure exactly what the best way to surface this is, but following the error messages led me down a long path. The messages make it appear that the particular character is the problem, when in reality it was a quote that was opened and never closed in a previous operation . For example: ``` conn.transact(&mut sqlite, r#"[ {:db/id 17592186049155, :artist/name "W} {:db/id 17592186049242, :artist/name "ö"} ]"#).unwrap(); ``` Leads to an error pointing to the `ö` character, which led me down a path of removing each 'invalid' character, one by one: ``` thread 'test_big' panicked at 'called `Result::unwrap()` on an `Err` value: Error(EdnParseError(ParseError { line: 3, column: 47, offset: 97, expected: {"[12]", "\t", "nil", "[0-9]", "\r", "[", "0x", "#f", "[*!_?$%&=<>]", "\"", "true", "{", ";", ".", ",", "+", "...", "[2-9]", "}", "(", "\n", "[a-z]", "-", " ", ":", "[A-Z]", "#{", "0", "false", "[3]"} }), State { next_error: None, backtrace: None })', src/libcore/result.rs:859 note: Run with `RUST_BACKTRACE=1` for a backtrace. ``` If you finally get to the last instance, i.e. ``` conn.transact(&mut sqlite, r#"[ {:db/id 17592186049155, :artist/name "W} {:db/id 17592186049242, :artist/name "o"} ]"#).unwrap(); ``` Then we end up with an error pointing to the final bracket: ``` thread 'test_big' panicked at 'called `Result::unwrap()` on an `Err` value: Error(EdnParseError(ParseError { line: 4, column: 6, offset: 106, expected: {"\\tab", "\"", "\\\"", "[^\"]"} }), State { next_error: None, backtrace: None })', src/libcore/result.rs:859 note: Run with `RUST_BACKTRACE=1` for a backtrace. ``` If there was some kind of context in the error message pointing to the origin of the opened string it would save a ton of time.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: greg/mentat#166
No description provided.