Skip to content

Releases: bdlm/errors

v2.2.1 - formatter fix (#23)

Choose a tag to compare

@mkenney mkenney released this 24 Aug 14:46
3d5ae77

Fixed

  • %v discarded the cause chain. Error() and %s returned the full message, while %v
    printed only the outermost frame — so a wrapped cause was recorded everywhere except where anyone
    looks for it. %v is the verb fmt.Println(err) uses and the one most loggers call.

v2.2.0: Match the standard library's As signature

Choose a tag to compare

@mkenney mkenney released this 21 Aug 18:59
3da1e1c

Changed

  • As now matches the standard library's signature, As(err error, target interface{}) bool,
    replacing As(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.go promises every method works with nil values; four did not.
    (*E).Error, (*E).Is and (*E).MarshalJSON dereferenced a nil receiver, and (*E).Is also
    panicked whenever the frame carried no annotation of its own — reflect.TypeOf(nil) returns a
    NIL reflect.Type, and calling Comparable on that panics rather than answering false. The
    package-level Is had the same flaw. Both now share a comparableErrors helper.
  • **New and Wrap corrupted any message contain

v2.1.4: Traverse multi-errors in Is and As

Choose a tag to compare

@mkenney mkenney released this 21 Aug 00:52
ca4b60c

Fixed

  • Is and As now traverse multi-errors. An error may wrap several causes — errors.Join, or
    fmt.Errorf with more than one %w — and those implement Unwrap() []error, which the
    single-error Unwrap cannot express.
  • Unwrap still returns nil for a multi-error, as std/errors.Unwrap does — there is no single
    previous error to return. This is now documented rather than implicit; callers walking a chain
    themselves must branch on Unwrap() []error.

v2.1.3: Make wrapped errors visible to the standard errors package

Choose a tag to compare

@mkenney mkenney released this 21 Aug 00:04
a191a75

Added

  • Interoperation tests against the standard library's errors package (interop_test.go).

Changed

  • func (e *E) Unwrap() error now returns the wrapped error itself. It previously re-boxed a
    wrapped error that did not implement std/errors.Error as &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
    own Unwrap, Is and As were never consulted. The consequence was that errors.As could only
    ever match *E, since no other concrete type was ever yielded, so anything built on errors.As
    could not see through a wrap. gRPC is the sharpest example: status.FromError is errors.As for an
    interface{ GRPCStatus() *Status }, so a wrapped status error was reported as codes.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) bool no longer ends the walk early. It returned the first link's Is
    answer directly; every *E has an Is method, so a false there 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) bool is unchanged and still searches the chain — the standard library calls
    that hook as ok && x.Is(target), so its answer never terminated errors.Is's own walk.
  • func (e *E) Error() string includes 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 through Error() rather than a %+v verb — 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

Choose a tag to compare

@mkenney mkenney released this 31 May 02:52

Changed

  • Updated various docs

v2.1.0

Choose a tag to compare

@mkenney mkenney released this 30 May 20:29
61c413c

Added

  • Additional documentation
  • Pre-generics implementation of As, returns the error instance when found

Changed

  • Upgrade to bdlm/std v2.1.0
  • Cleaner type checking in Is methods

Removed

  • deprecated Has methods, use Is instead

v2.0.1

Choose a tag to compare

@mkenney mkenney released this 03 May 04:01
88e4324

v2.0.0 - 2020-05-02

Changed

  • Refactoring to better implement the std/errors.Error interface

v2.0.0

Choose a tag to compare

@mkenney mkenney released this 02 May 22:38
ffe7a47

v2.0.0 - 2020-05-02

v2.0.0 is the production release of the v0.2.0 development branch.

Added

  • go.mod
  • github.com/bdlm/std/v2/errors interfaces

Changed

  • licence changed from BSD to MIT
  • replace interfaces with github.com/bdlm/std/v2/errors implementations
  • simplified formatting and marshalling logic
  • renamed GetCaller(error) std_err.Caller to Caller(error) std_err.Caller

Removed

  • unused code

v0.2.1

Choose a tag to compare

@mkenney mkenney released this 19 Jul 01:24

Added

  • Documentation and examples

Changed

  • Minor formatting updates and cleanup

v0.2.0

Choose a tag to compare

@mkenney mkenney released this 18 Jul 06:20
bc08913

This release is a full rewrite of the errors package. See the README for further details.

Added

  • Caller interface
  • Error interface
  • Exported methods
    • Errorf(msg string, data ...interface{}) Error
    • GetCaller(err error) Caller
    • Has(err, test error) bool
    • Is(err, test error) bool
    • Trace(e error) Error
    • Track(e error) Error

Changed

  • Exported methods
    • New(code std.Code, msg string, data ...interface{}) *Err
      • New(msg string) Error
    • Wrap(err error, code std.Code, msg string, data ...interface{}) *Err
      • Wrap(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