ubgo is in early alpha: libraries and APIs may still change.

Skip to content
ubgo Alpha

errx

One structured error type with stable identity, class, redactable fields, return traces and a wire codec.

go get github.com/ubgo/errx
Language
Go
Go version
1.24
Core deps
0 direct
Latest tag
none
License
Apache-2.0
Go modules
9

How it fits together

Highlights from the README

  • Stable identity — domain + code, separate from the human message, so dashboards and clients branch on it even when wording changes.
  • Expected / Defect / Cancelled class — middleware returns 4xx + retry, alerts on bugs, stays quiet on client-cancelled.
  • Operator vs end-user message — internal detail never leaks to clients.
  • Typed structured fields with per-field redaction — safe-by-default at any trust boundary; no redactable-string tax.
  • Retry & severity on the error itself — resilience and logging layers read it, not a type switch.
  • Lazy single-alloc stack + return-trace — ~15 ns capture, symbolized only when printed; plus where the error traveled.
  • Suppressed errors — a failing defer Close() never masks the real failure (a classic Go bug Go has no stdlib fix for).
  • Two-mode accumulation — collect every validation failure with field paths, not just the first.

Code from the README

err := errx.New("db: deadlock on user_orders").
    WithDomain("billing").WithCode("TX_RETRY").
    WithPublic("Something went wrong, please retry").
    WithRetryable(0).
    WithSafe("shard", "eu-1")          // safe field — survives to logs/wire
    // .With("token", secret)          // unsafe field — auto-redacted at any boundary

httpx.Write(w, r, err)                  // → 503 application/problem+json
slog.Error("request failed", "err", err) // structured, redacted, fingerprinted

From the errx README.

At a glance (from the README)

ModuleUse it forREADME
contrib/httpxRFC 9457 application/problem+json HTTP responses (zero extra deps)docs
contrib/grpcgoogle.rpc.Status + ErrorInfo/RetryInfo/LocalizedMessage/Helpdocs
contrib/connectConnectRPC errors with typed detailsdocs
contrib/graphqlgqlgen ErrorPresenter (extensions.code)docs
contrib/sentrySentry capture with the core fingerprint as the grouping keydocs
contrib/otelOpenTelemetry exception span events + trace/span correlationdocs
contrib/prometheuserrx_errors_total metrics by stable identitydocs
contrib/goerrIncremental migration from github.com/ubgo/goerrdocs