Merge pull request #27178 from osamakader/fix-system-commands-error-handling

cmd/podman/system: fix error handling in renumber and migrate commands
This commit is contained in:
openshift-merge-bot[bot]
2025-09-29 14:00:13 +00:00
committed by GitHub
2 changed files with 6 additions and 27 deletions

View File

@ -3,12 +3,8 @@
package system package system
import ( import (
"fmt"
"os"
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/domain/entities" "github.com/containers/podman/v5/pkg/domain/entities"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.podman.io/common/pkg/completion" "go.podman.io/common/pkg/completion"
@ -30,7 +26,7 @@ var (
Args: validate.NoArgs, Args: validate.NoArgs,
Short: "Migrate containers", Short: "Migrate containers",
Long: migrateDescription, Long: migrateDescription,
Run: migrate, RunE: migrate,
ValidArgsFunction: completion.AutocompleteNone, ValidArgsFunction: completion.AutocompleteNone,
} }
) )
@ -52,13 +48,6 @@ func init() {
_ = migrateCommand.RegisterFlagCompletionFunc(newRuntimeFlagName, completion.AutocompleteNone) _ = migrateCommand.RegisterFlagCompletionFunc(newRuntimeFlagName, completion.AutocompleteNone)
} }
func migrate(cmd *cobra.Command, args []string) { func migrate(cmd *cobra.Command, args []string) error {
if err := registry.ContainerEngine().Migrate(registry.Context(), migrateOptions); err != nil { return registry.ContainerEngine().Migrate(registry.Context(), migrateOptions)
fmt.Println(err)
// FIXME change this to return the error like other commands
// defer will never run on os.Exit()
os.Exit(define.ExecErrorCodeGeneric)
}
os.Exit(0)
} }

View File

@ -3,12 +3,8 @@
package system package system
import ( import (
"fmt"
"os"
"github.com/containers/podman/v5/cmd/podman/registry" "github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate" "github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/define"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"go.podman.io/common/pkg/completion" "go.podman.io/common/pkg/completion"
) )
@ -27,7 +23,7 @@ var (
Args: validate.NoArgs, Args: validate.NoArgs,
Short: "Migrate lock numbers", Short: "Migrate lock numbers",
Long: renumberDescription, Long: renumberDescription,
Run: renumber, RunE: renumber,
ValidArgsFunction: completion.AutocompleteNone, ValidArgsFunction: completion.AutocompleteNone,
} }
) )
@ -39,12 +35,6 @@ func init() {
}) })
} }
func renumber(cmd *cobra.Command, args []string) { func renumber(cmd *cobra.Command, args []string) error {
if err := registry.ContainerEngine().Renumber(registry.Context()); err != nil { return registry.ContainerEngine().Renumber(registry.Context())
fmt.Println(err)
// FIXME change this to return the error like other commands
// defer will never run on os.Exit()
os.Exit(define.ExecErrorCodeGeneric)
}
os.Exit(0)
} }