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

Implement legacy error handling #75

Merged
merged 1 commit into from
Dec 19, 2024
Merged

Implement legacy error handling #75

merged 1 commit into from
Dec 19, 2024

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Dec 17, 2024

In order to teach v2 how to mostly reproduce v1 errors, add internal.{TransformMarshalError,NewMarshalerError,TransformUnmarshalError} that can be called by v2 to transform a v2 error into a v1 error. These injected functions are only ever called if ReportLegacyErrorValues is set.

TransformMarshalError and TransformUnmarshalError are called in the top-level Marshal or Unmarshal function if an error occurs. NewMarshalerError is called if a user-defined Marshal method fails.

A JSONValue field is added to v2 SemanticError hold the entire copy of an invalid JSON value during unmarshal. This is primarily populated when trying to coerce a JSON number or string into a numeric value. This field is needed to faithfully reproduce a v1 UnmarshalTypeError, which sometimes holds the JSON value in the Value field.

The error positioning stored in UnmarshalTypeError was fixed such that it is derived from the JSON pointer.
However, instead of being '/'-delimited, it remains '.'-delimited to be consistent with historical precedence.
Unlike before, the position now includes Go array, slice, and map indexes. Note that the positioning information in UnmarshalTypeError has always been inconsistent and has also been unstable, so hopefully changing this is okay.

@dsnet dsnet force-pushed the legacy-errors branch 2 times, most recently from ac6e741 to 5faee06 Compare December 17, 2024 07:39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

In order to teach v2 how to mostly reproduce v1 errors,
add internal.{TransformMarshalError,NewMarshalerError,TransformUnmarshalError}
that can be called by v2 to transform a v2 error into a v1 error.
These injected functions are only ever called if ReportLegacyErrorValues is set.

TransformMarshalError and TransformUnmarshalError are called
in the top-level Marshal or Unmarshal functions if an error occurs.
NewMarshalerError is called if a user-defined Marshal method fails.

A JSONValue field is added to v2 SemanticError hold the entire copy
of an invalid JSON value during unmarshal. This is primarily populated
when trying to coerce a JSON number or string into a numeric value.
This field is needed to faithfully reproduce a v1 UnmarshalTypeError,
which sometimes holds the JSON value in the Value field.

The error positioning stored in UnmarshalTypeError was fixed
such that it is derived from the JSON pointer.
However, instead of being '/'-delimited, it remains '.'-delimited
to be consistent with historical precedence.
Unlike before, the position now includes Go array, slice, and map indexes.
Note that the positioning information in UnmarshalTypeError
has always been inconsistent and has also been unstable,
so hopefully changing this is okay.
@dsnet dsnet merged commit fd80825 into master Dec 19, 2024
8 checks passed
@dsnet dsnet deleted the legacy-errors branch December 19, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants