pkg / errors

Simple error handling primitives
https://godoc.org/github.com/pkg/errors
BSD 2-Clause "Simplified" License
8.18k stars 691 forks source link

StackTrace.Format with "%+v" includes a leading newline #230

Open segevfiner opened 4 years ago

segevfiner commented 4 years ago

https://play.golang.org/p/9pIaAGoKF1i

Fixing this might break formatting elsewhere, so needs to be done carefully.

puellanivis commented 4 years ago

Hm… https://github.com/pkg/errors/blob/master/stack.go#L113-L114

Yeah, it looks like we’re prefixing each frame output with a newline. This probably wasn’t noticed much, because the verbose formatting for errors themselves, was expecting this behavior and the output looked fine there, because it just doesn’t add a newline at the end of the error message, before dumping the stack frame.

More ideally, we probably only want newlines between frames, or after every frame. Both would then require the verbose formatting to inject a newline before getting to the frame output, but that’s pretty easy, and not really any sort of obstacle.

The arguments for “between each frame” vs “at the end of each frame” lies in how we consider the verbose output: