json icon indicating copy to clipboard operation
json copied to clipboard

error.line() returns 0 when the docs say the numbering starts at 1

Open yannham opened this issue 4 years ago • 1 comments

Amongst other things, I use serde_json to deserialize data that can be used directly as values in some programming language. This language has its own error reporting infrastructure, and thus must convert sede's error to its own error types, using serde_json::error::Errors methods to compute and translate line and number columns.

The documentation for the Errror::line() methods says that numbering start at 1, however when running serde_json on some file (pasted below), error.line() returns 0, which makes the interpreter crash with subtraction overflow because there's an error.line() - 1 computed as an unsigned integer somewhere.

This particular bug is easily fixed, but the documentation should make it crystal clear if and in which case the value returned by line() may be zero. Currently, it looks like it can't, and people may rely on this fact.

[EDIT: File removed, useless]

yannham avatar Feb 11 '21 15:02 yannham

Additional info: the actual error is json parse error: data did not match any variant of untagged enum Term. So the problem is maybe that this error is not located.

yannham avatar Feb 11 '21 15:02 yannham