-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix panic handling and add a new exit code and a test for panics #2997
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 👍
I don't see any drawbacks, and this gives us more flexibility like you said, while also logging the panic in external backends.
rootCmd.cmd.AddCommand(&cobra.Command{ | ||
Use: "panic", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
panic("oh no, oh no, oh no,no,no,no,no") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1dde205
to
cf4fd49
Compare
Because we started calling os.Exit() in a defer statement, we circumvented the regular handling of panics that bubble up to the top by the Go runtime. I could have removed the os.Exit() call from the defer, but handling panics ourselves in this way allows us to handle them exactly how we want, assign them their own unique exit code, and test the whole thing with an e2e test.
cf4fd49
to
e4265bb
Compare
Codecov Report
@@ Coverage Diff @@
## master #2997 +/- ##
==========================================
+ Coverage 76.90% 76.93% +0.03%
==========================================
Files 228 228
Lines 17043 17050 +7
==========================================
+ Hits 13107 13118 +11
+ Misses 3090 3086 -4
Partials 846 846
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 8 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
In #2833 we started calling
os.Exit()
in adefer
statement, so we inadvertently circumvented the regular handling of panics that bubble up to the top by the Go runtime.I could have removed the
os.Exit()
call from thedefer
, but I think this is better. Handling panics ourselves in this way is explicit, simpler to understand, and it allows us to handle them exactly how we want - including assigning them their own unique exit code, and test the whole thing with an e2e test.