What this package does not do¶
Deliberate absences and known constraints. Each is a decision rather than a gap waiting to be filled, except where it says otherwise.
No OpenTelemetry, and no RecordError¶
This package ships nothing that talks to OTEL.
Deciding an error is worth recording happens where a span is in scope, not where
the error is made. That belongs to gitlab.com/phpboyscout/go/observability,
which reaches what it needs through StackOf,
KindOf and Attrs. That is why those
are exported and renderable.
Only JSON is built in¶
errors/wire carries errors between processes, and JSON is its only
built-in format. Protobuf is a separate module, errors-protobuf, still to ship.
Any other format is a codec of your own. There is no HTTP or gRPC helper: the
edge reads the Accept value and writes the body itself.
Some things do not cross a process boundary¶
- An
slog.KindAnyattribute arrives as its string. - A wrapper type the receiver has no codec for arrives as a layer that keeps its message, kind and causes, but is not your type.
- A sentinel decodes to the instance only in a receiver that links the package declaring it.
- Stacks are not sent unless the sender asks, and arrive as frames, not as a
StackTrace. - A time arrives in UTC.
- A sentinel whose message changed between the sender's version and the receiver's decodes as an opaque leaf with the sender's message, not as the receiver's instance.
No dependencies, and that constrains the API¶
The package imports only the standard library, asserted by depfootprint_test.go
rather than left to review. An error package is imported by every module in the
estate, so it should be the lightest thing in the graph.
The visible consequence is WithAttrs taking
[]slog.Attr rather than a richer type of its own.
Stacks are bounded at 32 frames¶
Deep enough for any real call chain, shallow enough that an error on a hot path is not expensive. A chain deeper than that is truncated, and there is no option to raise the bound.
Errors are immutable once constructed¶
Every annotator returns a new error wrapping the old one. Nothing hands back a
mutable map for you to add to later, which is how tozd/go/errors does it, and
mutating an error after construction invites aliasing and races.
A sentinel carries no stack until you add one¶
NewSentinel captures no stack by design, because
at package scope the call site is initialisation. If you return a sentinel
directly, the error has no stack at all. Wrap it:
Is compares pointers, which do not survive a wire on their own¶
Is matches on identity. A sentinel decoded by errors/wire is the
same instance again because its kind was registered. One
decoded from anything else, or sent with an empty kind, is a different value and
will not match.
A leaf from Newf has no kind¶
KindOf returns "" for an error built from Newf or
Errorf that does not wrap a sentinel, and a slog record of it therefore has
no kind field. (New reports errors.basic.) Identity is something you
declare, not something inferred from a message, so an error you want to
alert on needs a sentinel at its leaf.
Hints and details de-duplicate; attributes do not¶
Hints and Details collapse identical strings
to one. Attrs keeps every attribute, including repeated
keys, because which one wins is the caller's decision.
If you attach the same hint at three levels you will see it once; the same attribute key at three levels appears three times.
Nothing here reports on an error's absence¶
There is no "assert this error was handled" tooling, no linting of unwrapped
returns, and no runtime warning for an error that was constructed and dropped.
That is the job of errcheck and the rest of the lint suite.