Hacker News new | ask | show | jobs
by mlunar 557 days ago
In Go you can do errorf("%w: %s", err, path) so that you get "file not found: foo/bar.json", while still being able to match on the wrapped error value with errors.Is(). The caller can do the same with this error and so on up the stack
1 comments

I dislike this style in Go. It adds a lot of noise to the source and essentially builds a stack trace manually. In Go 1.23 there is errors.Wrap() that adds the error stack automatically so maybe at some point Go will consider again adding some sugar for automatic error propagation.
Go errors in standard library does not support stack traces. errors.Wrap() only exists in github.com/pkg/errors package