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

Handling error code for defer functions #545

Merged
merged 1 commit into from
Jul 21, 2021
Merged

Handling error code for defer functions #545

merged 1 commit into from
Jul 21, 2021

Conversation

kuritka
Copy link
Collaborator

@kuritka kuritka commented Jul 13, 2021

related to #124

because of the metrics we have to run the deferred function even if an error occurred during main processing. Until now, we used to call os.Exit(1) in main if any error occurred. Unfortunately, os.exit skips the deferred function call.

The solution is implementation. In case of an error we call return instead of os.Exit, and os.Exit itself is a deferred function.

related to #124

because of the metrics we have to run the deferred function even if an error occurred during main processing. Until now, we used to call `os.Exit(1)` in main if any error occurred. Unfortunately, `os.exit` skips the deferred function call.

The solution is implementation. In case of an error we call `return` instead of `os.Exit`, and `os.Exit` itself is a deferred function.

goimports made some changes in terratest

Signed-off-by: kuritka <[email protected]>
Copy link
Member

@ytsarev ytsarev left a comment

Choose a reason for hiding this comment

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

@kuritka looks good! Just thinking, is it something we can send upstream to operator-sdk? If I am not mistaking the main structure is inherited from the generated code

@kuritka
Copy link
Collaborator Author

kuritka commented Jul 21, 2021

@ytsarev , thx. Yes it's inherited from generated code which doesn't contain any deferred functions. But yes, we can try to push upstream as template.

@kuritka kuritka merged commit 8253842 into master Jul 21, 2021
@kuritka kuritka deleted the prometheus_no3 branch July 21, 2021 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants