Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up undoStack.RunIfError #11

Merged
merged 1 commit into from
Mar 25, 2020
Merged

Fix up undoStack.RunIfError #11

merged 1 commit into from
Mar 25, 2020

Conversation

jeddenlea
Copy link
Contributor

First, with Go 1.14, the use of %w in a Printf context other than Errorf
causes 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:

defer undoStack.RunIfError(out, err)

...every value is evaluated at the point of defer, but the execution of
the function is what is actually deferred. err will be nil 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.

First, with Go 1.14, the use of `%w` in a Printf context other than Errorf
causes 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:

	defer undoStack.RunIfError(out, err)

...every value is evaluated at the point of `defer`, but the execution of
the function is what is actually deferred.  `err` will be `nil` 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.
Copy link
Member

@phamann phamann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

Thank you for finding and fixing these issues, @jeddenlea

@phamann phamann merged commit 5803f63 into master Mar 25, 2020
@phamann phamann deleted the jed/master branch March 25, 2020 16:28
@phamann phamann added the bug Something isn't working label Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants