feat: removes formatter from Error function#10
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors error formatting so that calling Error() returns only the inner error message, and introduces a new Format() function to apply the full formatter chain. Tests and examples have been updated to use Format() instead of relying on the default Error() formatting.
- Modify
Error.Error()to return only the inner error. - Add
Format()helper and adjust existing formatters. - Update tests and examples to call
Format()and adjust expected outputs.
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| with_test.go | Switch tests from err.Error() to Format(err) and updated expected strings. |
| value_test.go | Add new TestValueAllSlice and test empty/error value slicing. |
| root_error_test.go | Add test covering GetRootError with fmt.Errorf wrapping. |
| formatter_test.go | Update formatter tests to use GetFormatter(err)(err) and Format(). |
| formatter.go | Introduce Format() function and update formatter implementations. |
| example/main.go | Update example calls to use Format() instead of printing err. |
| error_test.go | Add tests for nil inner error and mixed error chains. |
| error.go | Change Error() to bypass default formatter and return inner error. |
| README.md | Extend example showing both Error() and Format() usage. |
be4ba44 to
588f28e
Compare
xico42
previously approved these changes
Jul 3, 2025
The default formatter was causing unwanted behavior with external wrapping methods, like fmt.Errorf, because of how the Error functions was implemented and the use of GetRootError. Some context was lost in those cases. The solution was to remove de formatter from the Error function. Now the Error function will only print the inner Error(). This will preserve the context of other errors. The formatters are still available to be used directly or by calling the new Format() function that will apply the formatter set in the error chain or the Default one. This was the previous behavior of the Error functions.
588f28e to
5511d76
Compare
xico42
approved these changes
Jul 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default formatter was caused unwanted behavior with external wrapping methods, like fmt.Errorf, because of how the Error functions was implemented and the use of GetRootError.
Some context was lost in those cases.
The solution was to remove de formatter from the Error function. Now the Error function will only print the inner Error(). This will preserve the context of other errors.
The formatters are still available to be used directly or vai calling the new Format() function that will apply the formatter set in the error chain or the Default one. This was the previous behavior of the Error functions.