Skip to content

Commit 71e60cc

Browse files
authored
fix incorrect defer exit(err) statements (#93)
When calling a function directly from a `defer` statement, like so: ```go var err error exit := someFuncReturningAFunctor() defer exit(err) ``` The `exit` function is passed the `err` variable by value, which means that the value of `err` will always be nil above. In order to have the deferred `exit` function use the value of the `err` variable *on exit of the function*, you need to wrap the `exit` call inside a temporary function, like so: ```go var err error exit := someFuncReturningAFunctor() defer func() { exit(err) }() ``` See here for more information about this odd behaviour: https://stackoverflow.com/questions/42703707/when-defer-func-evaluates-its-parameters The alternative solution here was to change `exit`'s call signature to accept a `*error` instead of an `error`, however we have code out there in the controllers that would break if we changed `exit`'s function signature. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1163c8e commit 71e60cc

34 files changed

+549
-45
lines changed

mocks/apimachinery/pkg/apis/meta/v1/object.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/cacheable_object.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/nested_object_decoder.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/nested_object_encoder.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object_convertor.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object_creater.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object_defaulter.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object_typer.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/apimachinery/pkg/runtime/object_versioner.go

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)