Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: special types: structured error #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pohly
Copy link
Contributor

@pohly pohly commented Nov 23, 2022

This is based on #60 and adds support for "structured errors" (see kubernetes/klog#357).

@pohly pohly changed the title RFC: special types: structured error and logr.KeysAndValues RFC: special types: structured error Sep 19, 2023
@pohly pohly force-pushed the special-types branch 2 times, most recently from ed3114f to 1809a60 Compare November 21, 2023 13:30
A "structured error" is an error which implements error and slog.LogValuer.
When encountering such an error, it gets logged normally and then another field
gets added with the result of LogValue().

The name of the extra field is the original field name plus a configurable
suffix, with "Details" as default.

The extra details are logged as if they had been passed as a value to
zapr. slog.Value.Resolve is used to protect against errors and recursion while
calling LogValue, but does not protect against recursion that can occur when
LogValue returns the original error: then zapIt->zapError->zapIt->... repeats
until the program gets killed.

A simple guard against this (not expanding error again while formatting an
error) is too simplistic and would prevent nice rendering of a wrapped error
that might get returned by MarshalLog. zapIt would have to track the exact
error instance and detect when it gets the same value again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant