attest icon indicating copy to clipboard operation
attest copied to clipboard

proposal: print errors using "%+v"

Open komuw opened this issue 1 year ago • 2 comments

Currently errors in attest.Ok() are printed using t.Printf("error: %v", err). This proposal is to change that to t.Printf("error: %+v", err). The rationale is, there are some 3rd party error libraries that add stack traces to their errors, for those they mostly use the + flag when you want to print the error and the trace.

Examples:

  1. pkg/errors ; https://github.com/pkg/errors/blob/5dd12d0cfe7f152f80558d591504ce685299311e/errors.go#L127-L132
  2. cockroachdb/errors; https://github.com/cockroachdb/errors/blob/c1cc1919cf999fb018fcd038852e969e3d5631cc/withstack/stack.go#L29-L36
  3. others; https://github.com/search?q=Flag%28%27%2B%27%29+language%3AGo++NOT+is%3Aarchived+&type=code

This issue is not about encouraging people to use error packages with stack traces, it is about improving the experience of those who do. Additionally people who do not use stack traces are not negatively affected by the change and finally it is not a huge change to the attest library.

komuw avatar May 12 '24 16:05 komuw

Sounds like a reasonable approach to me. Can you open a PR?

akshayjshah avatar May 12 '24 18:05 akshayjshah

opened; https://github.com/akshayjshah/attest/pull/17

komuw avatar May 13 '24 07:05 komuw

Friendly ping @akshayjshah

komuw avatar Aug 08 '24 11:08 komuw