Skip to content

all: simplify Go error wrapping

Administrator requested to merge backend-dry-run/rvt/wrap into main

Created by: rvantonder

Mechanical change based on @camdencheek comment.

Any stylistic concerns or is this good to merge (tests pass)?

FYI from the cockroachdb/errors docs:

// The following:
// if err := foo(); err != nil {
//    return errors.Wrap(err, "foo")
// }
// return nil
//
// is not needed. Instead, you can use this:
return errors.Wrap(foo(), "foo")
I know this is just copy/paste, so feel free to ignore to keep the change more isolated, but I've been attempting to evangelize some cleaner error patterns.

There are some other Wrapf and errors.Errorf calls that also simplify. I'll do those if this PR is positively received :-). query


Command:

comby \
'if err := :[v:e]; err != nil { return errors.Wrap(:[w], :[s]) } return nil' \
'return errors.Wrap(:[v], :[s])' \
'' \
-rg "-g '*.go'" -i

Merge request reports

Loading