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

zapcore: Support ObjectMarshaler for error types #1365

Open
sywhang opened this issue Sep 27, 2023 · 0 comments
Open

zapcore: Support ObjectMarshaler for error types #1365

sywhang opened this issue Sep 27, 2023 · 0 comments
Assignees

Comments

@sywhang
Copy link
Contributor

sywhang commented Sep 27, 2023

When error types implement the ObjectMarshaler interface and is logged as a zap.Error field, it is not respected by zapcore because we currently only respect the string returned by the error and fmt.Formatter interfaces.

We should prefer the ObjectMarshaler interface over either of these, since it provides a more flexible approach to log the error type.

Note that when the error object is logged via zap.Any or zap.Object, its ObjectMarshaler implementation will be respected.

@sywhang sywhang self-assigned this Sep 27, 2023
justinhwang added a commit to justinhwang/zap that referenced this issue Feb 7, 2024
Previously, implementing `ObjectMarshaler` on an error type was ignored
unless the error was logged with `zap.Any` or `zap.Object`. We should
respect the `ObjectMarshaler` instead as this is more flexible than the
basic `error` or `fmt.Formatter` interfaces.

Resolves uber-go#1365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant