feat(xerrors): initial stable release v0.9.0
Structured application errors with typed codes, cause chaining, key-value context fields, and zero-import logz enrichment bridge. What's included: - `*Err` type implementing error, errors.Unwrap, json.Marshaler, ErrorCode(), and ErrorContext() - Twelve typed Code constants aligned with gRPC canonical status names - New / Wrap factory constructors plus InvalidInput / NotFound / Internal convenience constructors - Builder methods WithContext and WithError for attaching structured fields and causes - Duck-typed ErrorCode() / ErrorContext() bridge so logz auto-enriches log records without an import Tested-via: todo-api POC integration Reviewed-against: docs/adr/
This commit is contained in:
24
compliance_test.go
Normal file
24
compliance_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package xerrors_test
|
||||
|
||||
import "code.nochebuena.dev/go/xerrors"
|
||||
|
||||
// Compile-time contract verification.
|
||||
//
|
||||
// These assertions are zero-cost at runtime — the nil pointers are never
|
||||
// dereferenced. If any method is removed or its signature changes, the build
|
||||
// fails immediately here rather than at a distant call site in another module.
|
||||
|
||||
// richError is the shape that logz and other consumers expect from any structured
|
||||
// error produced by this package. Adding methods to Err is non-breaking. Removing
|
||||
// any of these or changing their signature is a breaking change.
|
||||
var _ interface {
|
||||
error
|
||||
Unwrap() error
|
||||
ErrorCode() string
|
||||
ErrorContext() map[string]any
|
||||
} = (*xerrors.Err)(nil)
|
||||
|
||||
// jsonMarshaler verifies Err implements json.Marshaler.
|
||||
var _ interface {
|
||||
MarshalJSON() ([]byte, error)
|
||||
} = (*xerrors.Err)(nil)
|
||||
Reference in New Issue
Block a user