Skip to content

Commit

Permalink
cmd: Add an errtrace command (#11)
Browse files Browse the repository at this point in the history
Adds a new errtrace binary that instruments existing Go code
with errtrace.Wrap calls.

This operates by searching for functions that return errors,
and inside those functions, wrapping all returns with `errtrace.Wrap`.

To allow for future usage with -toolexec or similar,
the code edits all ensure that line numbers do not change.
We may want to reconsider this behavior in the future.

This works pretty well for the cases we tried it on except
multi-return functions made by automatic expansion:

    func foo() (int, error) {
        return bar()
    }

To support that, we'll need a generic `Wrap2[int]` function.
That'll be added in a future change separately.
  • Loading branch information
abhinav authored Nov 19, 2023
1 parent a73cb06 commit 2583784
Show file tree
Hide file tree
Showing 20 changed files with 1,252 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/errtrace/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/errtrace
Loading

0 comments on commit 2583784

Please sign in to comment.