Fix error masking in standalone runner #794
Merged
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.
Description
Currently our error masking within the standalone runner is broken. The runner always logs that an error has been masked even though there is no error. This happened because, in the check for masking the error
consumeErrorIfNecessary()
, we do not check for the error itself but for the pointer, which is never nil. Additionally the defer function set the wrong variable to nil becausedefer
runs a function after the return statement but before the function is actually returned, thus enabling modify returned results, but only named return results can be accessed normally. This caused that the error was set to nil, but not actual returned error, because go already evaluated the return result.More here: https://stackoverflow.com/questions/48680222/what-is-the-difference-between-named-return-value-and-normal-return-value
How can this be tested?
Before this PR
Deploy cloudNative or applicationMonitoring on a cluster and deploy sample apps. If you now check the logs of the initContainer, you can see the error log at the end of the run. Additionally if an error happens within the run and the failure policy is set to
silent
, the sample app would crash, because the initContainer is not finished successfully.After this PR
Deploy cloudNative or applicationMonitoring on a cluster and deploy sample apps. If you now check the logs of the initContainer, should not see any false error log anymore. Additionally if an error happens within the run and the failure policy is set to
silent
, the sample app is not crashing anymore and the initContainer finishes with 0 even though there was an error.Checklist