Copilot commented on code in PR #997:
URL: https://github.com/apache/dubbo-go-pixiu/pull/997#discussion_r3480495516
##########
pkg/cmd/gateway.go:
##########
@@ -63,20 +65,21 @@ var (
startGatewayCmd = &cobra.Command{
Use: "start",
Short: "Start gateway",
- PreRun: func(cmd *cobra.Command, args []string) {
+ PreRunE: func(cmd *cobra.Command, args []string) error {
initDefaultValue()
err := deploy.initialize()
if err != nil {
- panic(err)
+ return errors.Wrap(err, "failed to initialize
gateway")
}
+ return nil
},
- Run: func(cmd *cobra.Command, args []string) {
-
+ RunE: func(cmd *cobra.Command, args []string) error {
err := deploy.start()
if err != nil {
- panic(err)
+ return errors.Wrap(err, "failed to start
gateway")
}
+ return nil
Review Comment:
`RunE` returning an error will not currently translate to a non-zero process
exit because the root command ignores `Execute()` errors (in
`cmd/pixiu/pixiu.go`). As a result, gateway startup failures can be reported to
stderr but still return success to the caller.
##########
pkg/cmd/gateway.go:
##########
@@ -63,20 +65,21 @@ var (
startGatewayCmd = &cobra.Command{
Use: "start",
Short: "Start gateway",
- PreRun: func(cmd *cobra.Command, args []string) {
+ PreRunE: func(cmd *cobra.Command, args []string) error {
initDefaultValue()
err := deploy.initialize()
if err != nil {
- panic(err)
+ return errors.Wrap(err, "failed to initialize
gateway")
Review Comment:
`PreRunE` now returns an error on initialization failure, but the CLI
entrypoint currently ignores the return value from `Execute()` (see
`cmd/pixiu/pixiu.go`), which means the process can exit with status 0 even when
initialization fails. For a startup command, this is an operational regression
vs the previous panic-based behavior and can break scripts/health checks that
rely on exit codes.
Please update the root command execution to handle `Execute()` errors (e.g.,
`os.Exit(1)`), or otherwise ensure non-zero exit codes on startup failures
(while keeping any README example constraints).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]