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

Review logs to use %v and %w correctly #1518

Closed
arnaubennassar opened this issue Jan 7, 2023 · 1 comment · Fixed by #1764
Closed

Review logs to use %v and %w correctly #1518

arnaubennassar opened this issue Jan 7, 2023 · 1 comment · Fixed by #1764
Labels
bug Something isn't working improvement

Comments

@arnaubennassar
Copy link
Member

When we log errors using %w but the error is actually not wrapped to contain the trace, the error message is actually not logged. A pattern that we could use is to:

  • Always log the error with %v at the deepest point in the stack (when it's generated), and wrap it here
  • Log again in the highest point in the stack using %w
@arnaubennassar arnaubennassar added bug Something isn't working improvement labels Jan 7, 2023
@tclemos
Copy link
Contributor

tclemos commented Jan 7, 2023

I think there is a misunderstanding here.

We don't have to wrap errors when logging, we need to wrap when returning it.

We must never use %w for logs
We must always use %w when rethrowing errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working improvement
Projects
None yet
2 participants