fix(cmd): return an error instead of panic#820
Conversation
|
There was a problem hiding this comment.
Pull request overview
Updates the start CLI command to return errors to Cobra instead of panicking, improving runtime robustness and allowing the CLI to exit cleanly on configuration/startup failures.
Changes:
- Switch
startcommand handler fromRuntoRunE. - Replace
panic(err)with returned, wrapped errors for config unmarshalling. - Return
Start(...)error directly to the CLI framework.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| panic(err) | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := viper.Unmarshal(&conf); err != nil { | ||
| return fmt.Errorf("unable to read configuration file: %w", err) |
There was a problem hiding this comment.
The error text is misleading: viper.Unmarshal can fail due to decode/type issues from flags/env as well, not just reading a configuration file. Consider changing the message to reflect unmarshalling/decoding (e.g., "unable to decode configuration") or include the config source when known.
| return fmt.Errorf("unable to read configuration file: %w", err) | |
| return fmt.Errorf("unable to decode configuration: %w", err) |
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := viper.Unmarshal(&conf); err != nil { | ||
| return fmt.Errorf("unable to read configuration file: %w", err) | ||
| } | ||
|
|
||
| err = Start(cmd.Context(), conf) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| return Start(cmd.Context(), conf) |
There was a problem hiding this comment.
This change switches the command to RunE and introduces a new error-returning path (instead of panicking) when config unmarshalling fails. There doesn't appear to be a test that asserts start returns an error (and does not panic) for an invalid config value; adding one would prevent regressions and validate the new behavior.
|
|
✅ All tests successful. No failed tests were found. 📣 Thoughts on this report? Let Codecov know! | Powered by Codecov |
Codecov Report❌ Patch coverage is
|



No description provided.