fatih / errwrap

Go tool to wrap and fix errors with the new %w verb directive
https://arslan.io
Other
371 stars 16 forks source link

errwrap -fix needs multiple invocations if there are a number of wrappings to perform in a file #11

Closed dnwe closed 4 years ago

dnwe commented 4 years ago

Is there an intentional limit on the number of fixes to apply in a single invocation? I noticed that if I use errwrap to attempt to migrate a legacy project to using 1.13 style error wrapping, it takes a few invocations to make it fix everything:

% errwrap -fix .
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:86:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:89:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:92:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:95:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:98:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:101:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:126:10: call could wrap the error with error-wrapping directive %w

% errwrap -fix .
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:98:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:95:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:101:10: call could wrap the error with error-wrapping directive %w
/Users/example/.local/src/github.ibm.com/org/repo/pkg/action/metrics/screenshot.go:126:10: call could wrap the error with error-wrapping directive %w

% errwrap -fix .

%
fatih commented 4 years ago

Hi @dnwe,

I'm sure we don't do anything special in errwrap. But we're using the golang.org/x/tools/go/analysis package and I think maybe there is some special logic that shortcuts printing diagnostics error to not spam the terminal and that logic might be tied to fixing code as well. One thing worth testing is to upgrade the tooling package to see whether it changes anything for you (run these inside the cloned errwrap repo):

go get -u golang.org/x/tools
go install // or go build -o ...
dnwe commented 4 years ago

@fatih thanks for the confirmation. By coincidence I did bump golang.org/x/tools as part of my PR https://github.com/fatih/errwrap/pull/12 — but I think you're right and its probably the built in "don't report too many errors to stdout" that is also applied to the -fix behaviour