Skip to content

Conversation

@p-sherratt
Copy link

@p-sherratt p-sherratt commented Apr 22, 2025

Adds a new error type, UnmarshalerError which is used to wrap any errors returned from decodeByUnmarshaler

Closes #704

@p-sherratt p-sherratt changed the title feat: implement UnmarshalerError #704 feat: implement UnmarshalerError Apr 22, 2025
@codecov-commenter
Copy link

codecov-commenter commented Apr 22, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.

Project coverage is 78.01%. Comparing base (500180b) to head (3a13581).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #705      +/-   ##
==========================================
+ Coverage   77.94%   78.01%   +0.06%     
==========================================
  Files          22       22              
  Lines        7998     7996       -2     
==========================================
+ Hits         6234     6238       +4     
+ Misses       1349     1345       -4     
+ Partials      415      413       -2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@goccy goccy requested a review from Copilot May 5, 2025 14:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new error type, UnmarshalerError, to wrap errors produced by the decodeByUnmarshaler function and prevent double-wrapping of errors.

  • Adds the UnmarshalerError struct and its associated methods in internal/errors/error.go
  • Exposes UnmarshalerError via the root error.go file
  • Updates decode.go to wrap errors from decodeByUnmarshaler (and map-key decoding) using ErrUnmarshal

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
internal/errors/error.go Added new UnmarshalerError type and error formatting
error.go Exposed UnmarshalerError via an alias
decode.go Updated error returns to wrap decoding errors with ErrUnmarshal

Copy link
Owner

@goccy goccy left a comment

Choose a reason for hiding this comment

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

Please add the test case for this changes

@goccy goccy added reviewed waiting owner is waiting for a response labels May 5, 2025
@p-sherratt p-sherratt force-pushed the add-unmarshaler-error branch from a1d59f0 to 3a13581 Compare May 20, 2025 20:47
@p-sherratt p-sherratt requested a review from goccy May 20, 2025 20:53
}
var te *errors.TypeError
if errors.As(err, &te) {
if te, ok := err.(*errors.TypeError); ok {
Copy link
Owner

Choose a reason for hiding this comment

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

I think this will stop working if the err is wrapped somewhere. Why did you change the sequence using As ?

})
}

func TestUnmarshalableErrors(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

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

There is only a test case for UnmarshalYAML([]byte) error, so please add tests for other cases as well. In the tests, ensure that you can obtain an UnmarshalerError and verify that the content of its Error() matches the expected message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewed waiting owner is waiting for a response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement UnmarshalerError for friendlier error formatting

3 participants