Re: [go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-23 Thread 'Axel Wagner' via golang-nuts
On Mon, Mar 23, 2020 at 10:28 AM Adrian Ratnapala < adrian.ratnap...@gmail.com> wrote: > I think this is the classic dynamic vs. static typing trade-off. I don't fully agree here - I think it's perfectly possible to have all of the flexibility and all of the static type-checking. I'm having trou

Re: [go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-23 Thread Adrian Ratnapala
On Mon, 23 Mar 2020 at 11:22, Axel Wagner wrote: > • A function takes an io.Reader to parse the stream into some data structure > (think a json-parser). It obviously uses no other input or abstraction or > state. It makes sense to wrap the error - this allows you to provide > structured extra

Re: [go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-22 Thread 'Axel Wagner' via golang-nuts
Yes, IMO the decision to expose errors should in general be deliberate. However, there are cases where it makes sense to wrap from the get-go. Two examples: • A function takes an io.Reader to parse the stream into some data structure (think a json-parser). It obviously uses no other input or abstr

Re: [go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-22 Thread Marcin Romaszewicz
In my opinion, this is a much nicer errors package than Go's library, and I've been using it everywhere: https://github.com/pkg/errors Instead of fmt.Errorf("%w"), you do errors.Wrap(err, "message"), and errors.Unwrap(...) where you want to inspect the error. It's much more explicit and less error

[go-nuts] If in doubt prefer to wrap errors with %v, not %w?

2020-03-22 Thread Adrian Ratnapala
Part of the culture of Go is that we are careful to promise as little as possible in APIs, as we will be stuck with those promises long into the future. Now with Go 1.13 we can do `fmt.Errorf("It broken: %w")` which means the same thing as `fmt.Errorf("It broken: %v")` except callers get better w