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

chore: prefer to panic instead of os.Exit #15285

Merged
merged 2 commits into from
Mar 7, 2023
Merged

Conversation

mark-rushakoff
Copy link
Member

Description

In a few call sites that used os.Exit, prefer to panic, in order to allow any deferred cleanup to happen before process termination.

Moreover, a panic in a test is a clear failure, but an os.Exit(1) that occurs during a test causes an obscure test failure that is difficult to track down.

Also move server/util.TrapSignal to an unexported function near its only use, to discourage one more outstanding use of os.Exit.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code

In a few call sites that used os.Exit, prefer to panic, in order to
allow any deferred cleanup to happen before process termination.

Moreover, a panic in a test is a clear failure, but an os.Exit(1) that
occurs during a test causes an obscure test failure that is difficult to
track down.

Also move server/util.TrapSignal to an unexported function near its only
use, to discourage one more outstanding use of os.Exit.
@mark-rushakoff mark-rushakoff requested a review from a team as a code owner March 6, 2023 19:08
@@ -352,30 +352,6 @@ func ExternalIP() (string, error) {
return "", errors.New("are you connected to the network?")
}

// TrapSignal traps SIGINT and SIGTERM and terminates the server correctly.
func TrapSignal(cleanupFunc func()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a changelog for that?

@tac0turtle tac0turtle enabled auto-merge (squash) March 7, 2023 14:52
@tac0turtle tac0turtle merged commit 1bb632a into main Mar 7, 2023
@tac0turtle tac0turtle deleted the mr/panic-instead-of-os-exit branch March 7, 2023 15:12
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
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.

5 participants