• v1.0.0 c6ff8d0a3f

    Rene Nochebuena released this 2026-05-11 17:51:16 -06:00 | 1 commits to main since this release

    v1.0.0

    code.nochebuena.dev/go/xerrors

    Overview

    xerrors v1.0.0 commits the structured error API as stable. All v0.9.0 roadmap
    items are resolved. The module ships five convenience constructors covering the
    most-used error codes, a complete set of thirteen typed codes aligned with gRPC
    canonical status names, and the zero-import logz enrichment bridge that has been
    validated in production across sei-api and the httpauth middleware stack.

    What Changed Since v0.10.0

    New: Unauthorized and PermissionDenied convenience constructors

    func Unauthorized(msg string, args ...any) *Err
    func PermissionDenied(msg string, args ...any) *Err
    

    Completes the convenience constructor set. The five most-used codes now have
    dedicated constructors:

    Constructor Code
    InvalidInput(msg, args...) ErrInvalidInput
    NotFound(msg, args...) ErrNotFound
    Internal(msg, args...) ErrInternal
    Unauthorized(msg, args...) ErrUnauthorized (new)
    PermissionDenied(msg, args...) ErrPermissionDenied (new)

    Less-used codes continue to use New or Wrap directly.

    Roadmap items resolved

    Item Resolution
    Validate all codes in production Validated in sei-api and httpauth stack
    Codes registry / lookup helper Decision: No — transport mapping belongs in httputil
    ErrorContext() read-only contract Documented in godoc since v0.10.0
    Additional convenience constructors Unauthorized and PermissionDenied added
    Production validation of logz bridge Concurrent load validated

    Full API (stable)

    Code type — string alias; thirteen constants (ErrInvalidInput, ErrUnauthorized,
    ErrPermissionDenied, ErrNotFound, ErrAlreadyExists, ErrGone,
    ErrPreconditionFailed, ErrRateLimited, ErrCancelled, ErrInternal,
    ErrNotImplemented, ErrUnavailable, ErrDeadlineExceeded).
    HTTP mapping belongs to the transport layer; see httputil for the reference implementation.

    New(code, message) *Err — primary factory.

    Wrap(code, message, cause) *Err — wraps an existing error.

    InvalidInput(msg, args...) *ErrErrInvalidInput.

    NotFound(msg, args...) *ErrErrNotFound.

    Internal(msg, args...) *ErrErrInternal.

    Unauthorized(msg, args...) *ErrErrUnauthorized. (New in v1.0.0)

    PermissionDenied(msg, args...) *ErrErrPermissionDenied. (New in v1.0.0)

    (*Err).WithContext(key, value) *Err — attach a key-value field; chainable.

    (*Err).WithError(err) *Err — set or replace the cause; chainable.

    (*Err).WithPlatformCode(code) *Err — domain-level code for frontend i18n; chainable.

    (*Err).Code() Code, Message() string, PlatformCode() string,
    Fields() map[string]any, Detailed() string — accessors.

    (*Err).ErrorCode() string and (*Err).ErrorContext() map[string]any
    duck-type bridge for logz automatic enrichment; read-only contract on ErrorContext.

    (*Err).MarshalJSON(){"code":"...","platformCode":"...","message":"...","fields":{...}}.

    Migration from v0.10.0

    No breaking changes. The only additions are Unauthorized and PermissionDenied.

    go get code.nochebuena.dev/go/xerrors@v1.0.0
    
    Downloads