Repository navigation
Releases: bdlm/errors
Releases · bdlm/errors
Release list
v2.2.1 - formatter fix (#23)
Fixed
%vdiscarded the cause chain.Error()and%sreturned the full message, while%v
printed only the outermost frame — so a wrapped cause was recorded everywhere except where anyone
looks for it.%vis the verbfmt.Println(err)uses and the one most loggers call.
v2.2.0: Match the standard library's As signature
Changed
Asnow matches the standard library's signature,As(err error, target interface{}) bool,
replacingAs(err, test error) error.
Fixed
Eight defects, all found by a new contract test suite (contract_test.go) organised by obligation
rather than by function. Coverage 95.9%, race-clean.
- Panics on nil.
doc.gopromises every method works with nil values; four did not.
(*E).Error,(*E).Isand(*E).MarshalJSONdereferenced a nil receiver, and(*E).Isalso
panicked whenever the frame carried no annotation of its own —reflect.TypeOf(nil)returns a
NILreflect.Type, and callingComparableon that panics rather than answering false. The
package-levelIshad the same flaw. Both now share acomparableErrorshelper. - **
NewandWrapcorrupted any message contain
v2.1.4: Traverse multi-errors in Is and As
Fixed
IsandAsnow traverse multi-errors. An error may wrap several causes —errors.Join, or
fmt.Errorfwith more than one%w— and those implementUnwrap() []error, which the
single-errorUnwrapcannot express.Unwrapstill returnsnilfor a multi-error, asstd/errors.Unwrapdoes — there is no single
previous error to return. This is now documented rather than implicit; callers walking a chain
themselves must branch onUnwrap() []error.
v2.1.3: Make wrapped errors visible to the standard errors package
Added
- Interoperation tests against the standard library's
errorspackage (interop_test.go).
Changed
func (e *E) Unwrap() errornow returns the wrapped error itself. It previously re-boxed a
wrapped error that did not implementstd/errors.Erroras&E{err: prev}. That box carried no
prev, so the chain ended there and the original error value was never handed to the caller — its
ownUnwrap,IsandAswere never consulted. The consequence was thaterrors.Ascould only
ever match*E, since no other concrete type was ever yielded, so anything built onerrors.As
could not see through a wrap. gRPC is the sharpest example:status.FromErroriserrors.Asfor an
interface{ GRPCStatus() *Status }, so a wrapped status error was reported ascodes.Unknown— an
HTTP 500 — including for failures that were plainly the caller's fault, such as an unacceptable auth
token.func Is(err, test error) boolno longer ends the walk early. It returned the first link'sIs
answer directly; every*Ehas anIsmethod, so afalsethere ended the search and a sentinel
further down was unreachable. A negative answer from one link now continues to the next.
func (e *E) Is(error) boolis unchanged and still searches the chain — the standard library calls
that hook asok && x.Is(target), so its answer never terminatederrors.Is's own walk.func (e *E) Error() stringincludes the wrapped message,"outer: inner", as
fmt.Errorf("%w")produces. Returning only the frame's own message discarded everything beneath it
wherever an error is rendered throughError()rather than a%+vverb — which is most of the
places that reach a user, including an HTTP or gRPC response body. The trace and JSON formats print
one line per frame and now use each frame's own message, so their output is unchanged.
v2.1.1
v2.1.0
v2.0.1
v2.0.0
v2.0.0 - 2020-05-02
v2.0.0 is the production release of the v0.2.0 development branch.
Added
go.modgithub.com/bdlm/std/v2/errorsinterfaces
Changed
- licence changed from BSD to MIT
- replace interfaces with
github.com/bdlm/std/v2/errorsimplementations - simplified formatting and marshalling logic
- renamed
GetCaller(error) std_err.CallertoCaller(error) std_err.Caller
Removed
- unused code
v0.2.1
v0.2.0
This release is a full rewrite of the errors package. See the README for further details.
Added
CallerinterfaceErrorinterface- Exported methods
Errorf(msg string, data ...interface{}) ErrorGetCaller(err error) CallerHas(err, test error) boolIs(err, test error) boolTrace(e error) ErrorTrack(e error) Error
Changed
- Exported methods
New(code std.Code, msg string, data ...interface{}) *ErrNew(msg string) Error
Wrap(err error, code std.Code, msg string, data ...interface{}) *ErrWrap(e error, msg string, data ...interface{}) Error
Removed
- Exported methods
From(code std.Code, err error) *Err
- Support for error codes
- Support for sanitized vs raw error messages
- Support for HTTP status codes