Skip to content

define types for "structured error"#415

Open
pohly wants to merge 2 commits into
go-logr:masterfrom
pohly:pseudo-error
Open

define types for "structured error"#415
pohly wants to merge 2 commits into
go-logr:masterfrom
pohly:pseudo-error

Conversation

@pohly

@pohly pohly commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

This corresponds to changes proposed for klog in kubernetes/klog#361 and zapr in go-logr/zapr#56.

We do not strictly need these type definitions in logr, but having them here makes it more likely that different logr backends behave consistently. For that reason the PseudoStruct type should also better be defined in the main package. In addition, it avoids having a funcr dependency in other logging backends when they implement this type.

pohly added 2 commits January 23, 2026 17:31
ErrorDetailer can be used to extend how error values are logged. klog and zapr
will support this interface and other backends might want to do the same,
therefore it makes sense to define this interface and the associated convention
in logr.
Other logging backends than funcr may want to implement the same kind of
support for PseudoStruct, to increase portability and/or because it is useful.
For example, klog can render PseudoStruct a bit more nicely than arbitrary
structs because klog itself iterates over "fields".

Having the type in the main package avoids a dependency on the funcr package.
With a type alias this is not a breaking API change in logr.
Comment thread funcr/funcr.go

// PseudoStruct is a list of key-value pairs that gets logged as a struct.
type PseudoStruct []any
type PseudoStruct = logr.PseudoStruct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apidiff flags this as an API change:

  • PseudoStruct: changed from PseudoStruct to github.com/go-logr/logr.PseudoStruct

I'm not sure whether this is really a problem. Type aliases are meant to support such refactoring without breaking a Go API.

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.

2 participants