Skip to content

Conversation

@denisvmedia
Copy link
Member

@denisvmedia denisvmedia commented Jan 15, 2026

Description

This PR introduces a new compat sub-package that provides compatibility functions accepting standard Go error interface instead of requiring errx.Classified types. 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

  • New feature (non-breaking change that adds functionality)
  • Documentation update

Related Issues

This addresses criticism about the main package requiring errx.Classified types, making it harder to work with standard errors and third-party libraries.

Changes Made

  • Created new compat sub-package with Wrap() and Classify() functions
  • Functions accept standard error interface for classifications
  • Internal errorWrapper type converts standard errors to errx.Classified
  • Comprehensive package documentation explaining design decisions and tradeoffs
  • Added compat/README.md with usage examples and guidance
  • Created 16 unit tests covering all functionality
  • Created 8 example tests demonstrating usage patterns
  • Updated parent README.md to document the compat package
  • Updated CHANGELOG.md with compat package additions

Testing

Test Coverage

  • All new code is covered by tests
  • All existing tests pass (go test ./...)
  • Tests pass with race detector (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 is documented with godoc comments
  • README updated (if applicable)
  • CHANGELOG updated
  • Examples added/updated (if applicable)

Code Quality

  • Code follows the project's style guidelines
  • golangci-lint passes (golangci-lint run)
  • go vet passes
  • go fmt has been run
  • No new warnings introduced

Breaking Changes

Does this PR introduce breaking changes?

  • Yes
  • No

This is a purely additive change. The new compat package is optional and does not affect existing code.

Performance Impact

  • No performance impact
  • Performance improvement (include benchmarks)
  • Potential performance regression (explain why acceptable)

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:

  1. No stacktrace mirrors: Intentionally excluded to encourage explicit stacktrace.Here() usage when stack traces are needed
  2. Internal conversion: Uses errorWrapper to convert standard errors to errx.Classified while preserving error identity
  3. Nil-safe: Both functions return nil when cause is nil, matching main package behavior

Use Cases:

  • Migrating existing codebases to errx
  • Integrating with third-party libraries using standard errors
  • Codebases that prefer standard error interface flexibility

Tradeoffs:

  • ✅ More flexible for standard error interface users
  • ✅ Easier migration path
  • ⚠️ Less type safety
  • ⚠️ Slight performance overhead

Checklist

  • My code follows the code style of this project
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • I have updated the documentation accordingly
  • I have added an entry to CHANGELOG.md

This commit introduces a new compat sub-package that provides mirror
functions for errx's core wrapping and classification operations, but
accepts standard Go error interface instead of requiring errx.Classified
types.

Key features:
- compat.Wrap() and compat.Classify() accept error interface
- Internal conversion to errx.Classified preserves error identity
- Seamless integration with all errx features (sentinels, displayable, attributes)
- Full compatibility with errors.Is() and errors.As()

Benefits:
- Easier migration from existing error handling code
- Better integration with third-party libraries using standard errors
- More flexible for codebases preferring standard error interface

Tradeoffs:
- Less type safety compared to main package
- Slight overhead from additional wrapping layer
- Intentionally excludes stacktrace mirrors (use stacktrace.Here() explicitly)

Documentation:
- Comprehensive package documentation explaining design decisions
- README.md with usage examples and tradeoffs
- 16 unit tests + 8 example tests (all passing)
- Updated parent README.md with compat package information

This addresses feedback about the main package being too restrictive
while maintaining the benefits of the sealed interface pattern in the
core package.
Copilot AI review requested due to automatic review settings January 15, 2026 10:28
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 compat sub-package that provides wrapper functions accepting standard Go error interface instead of requiring errx.Classified types, addressing feedback about the main package being too restrictive.

Changes:

  • Created compat sub-package with Wrap() and Classify() functions that accept standard errors
  • Implemented internal errorWrapper type to convert standard errors to errx.Classified
  • Added comprehensive documentation, tests (16 unit tests + 8 examples), and README

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
compat/compat.go Core implementation with errorWrapper and conversion functions
compat/compat_test.go Unit tests covering all functionality including edge cases
compat/example_test.go Example tests demonstrating usage patterns
compat/README.md Package documentation with usage examples and design rationale
README.md Updated main README to document the compat package

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Remove unused receiver parameter in IsClassified method
- Fix whitespace/formatting issues (gofmt)
Copilot AI review requested due to automatic review settings January 15, 2026 10:33
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@denisvmedia denisvmedia added this pull request to the merge queue Jan 15, 2026
Merged via the queue into master with commit db28c81 Jan 15, 2026
8 checks passed
@denisvmedia denisvmedia deleted the feature/compat-package branch January 15, 2026 10:36
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