Add compat package for standard error interface compatibility #4
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.
Description
This PR introduces a new
compatsub-package that provides compatibility functions accepting standard Goerrorinterface instead of requiringerrx.Classifiedtypes. This addresses feedback about the main package being too restrictive while maintaining the benefits of the sealed interface pattern in the core package.Type of Change
Related Issues
This addresses criticism about the main package requiring
errx.Classifiedtypes, making it harder to work with standard errors and third-party libraries.Changes Made
compatsub-package withWrap()andClassify()functionserrorinterface for classificationserrorWrappertype converts standard errors toerrx.Classifiedcompat/README.mdwith usage examples and guidanceREADME.mdto document the compat packageCHANGELOG.mdwith compat package additionsTesting
Test Coverage
go test ./...)go test -race ./...)Manual Testing
All 24 tests in the compat package pass (16 unit tests + 8 examples). The package integrates seamlessly with existing errx features including sentinels, displayable errors, and attributes.
Documentation
Code Quality
golangci-lint run)go vetpassesgo fmthas been runBreaking Changes
Does this PR introduce breaking changes?
This is a purely additive change. The new compat package is optional and does not affect existing code.
Performance Impact
The compat package has slightly more overhead than the main package due to the additional wrapping layer that converts standard errors to
errx.Classified. This is an acceptable tradeoff for the flexibility it provides. Users who need maximum performance should continue using the main package.Additional Notes
Design Decisions:
stacktrace.Here()usage when stack traces are needederrorWrapperto convert standard errors toerrx.Classifiedwhile preserving error identityUse Cases:
Tradeoffs:
Checklist