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

provide a way to return from main function with non-zero exit code and run all deferred function #42078

Closed
ghost opened this issue Oct 19, 2020 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@ghost
Copy link

ghost commented Oct 19, 2020

os.Exit allows to set a non-zero status code, but it exit the program immediately and no deferred functions are run.

@davecheney
Copy link
Contributor

panic?

@ghost
Copy link
Author

ghost commented Oct 19, 2020

panic?

no.

@ianlancetaylor
Copy link
Contributor

func main() {
    os.Exit(realMain())
}

func realMain() int {
    ...
    return 1
}

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 20, 2020
@mdlayher
Copy link
Member

Since the author deleted their account and Ian provided an easy solution, I'm going to close this.

@golang golang locked and limited conversation to collaborators Oct 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants