Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, with Go 1.14, the use of
%w
in a Printf context other than Errorfcauses a vet error.
%w
is a special trigger to Errorf to create a"wrapped" error. What you'd want to do instead is either
%s
or%v
.However, given the nature of error strings, the behavior of simply
concatenating them together to
w
seems inappropriate. If anything,they should at least occur on seperate lines, so Fprintln seems more
appropriate.
Second, RunIfError's comment and invocation in Exec made apparent
another bug. As written, the undo stack would never actually execute.
As directed, if you were to:
...every value is evaluated at the point of
defer
, but the execution ofthe function is what is actually deferred.
err
will benil
there,and thus the undo stack is never actually executed.
This simple fix there is to actually defer a closure. When an error is
returned, it will then be observable from within the closure.