You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What would you like to be added:
When attempting to decode Syft JSON (or other formats), error messages do not show what line/character an error occurred, making it very difficult to understand what's wrong or how to fix it.
Why is this needed:
A user is unable to proceed when unable to parse a Syft JSON file.
Additional context:
It looks like there is a fairly simple way to get more information about parser errors when decoding JSON. See this article.
The gist is, the error returned from json.Unmarshal needs to be tested for types: *json.SyntaxError and *json.UnmarshalTypeError. Both of these types provide a .Offset field which is the character offset where an error occurred. From there we can write a simple function to extract the line text, line number, and character number to provide a nicely formatted message about the error, something like:
What would you like to be added:
When attempting to decode Syft JSON (or other formats), error messages do not show what line/character an error occurred, making it very difficult to understand what's wrong or how to fix it.
Why is this needed:
A user is unable to proceed when unable to parse a Syft JSON file.
Additional context:
It looks like there is a fairly simple way to get more information about parser errors when decoding JSON. See this article.
The gist is, the error returned from
json.Unmarshal
needs to be tested for types:*json.SyntaxError
and*json.UnmarshalTypeError
. Both of these types provide a.Offset
field which is the character offset where an error occurred. From there we can write a simple function to extract the line text, line number, and character number to provide a nicely formatted message about the error, something like:The original function outlined in the article is, which could easily be modified for our needs:
This is related to #1351
The text was updated successfully, but these errors were encountered: