akshayjshah / attest

Type-safe assertion helpers for Go
https://pkg.go.dev/go.akshayshah.org/attest
MIT License
15 stars 2 forks source link

proposal: print errors using "%+v" #16

Open komuw opened 2 months ago

komuw commented 2 months ago

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.

akshayjshah commented 2 months ago

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

komuw commented 2 months ago

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