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
import (
"fmt"
"os"
"github.com/containers/podman/v5/cmd/podman/registry"
"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/spf13/cobra"
"go.podman.io/common/pkg/completion"
@ -30,7 +26,7 @@ var (
Args: validate.NoArgs,
Short: "Migrate containers",
Long: migrateDescription,
Run: migrate,
RunE: migrate,
ValidArgsFunction: completion.AutocompleteNone,
}
)
@ -52,13 +48,6 @@ func init() {
_ = migrateCommand.RegisterFlagCompletionFunc(newRuntimeFlagName, completion.AutocompleteNone)
}
func migrate(cmd *cobra.Command, args []string) {
if err := registry.ContainerEngine().Migrate(registry.Context(), migrateOptions); err != nil {
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)
func migrate(cmd *cobra.Command, args []string) error {
return registry.ContainerEngine().Migrate(registry.Context(), migrateOptions)
}

View File

@ -3,12 +3,8 @@
package system
import (
"fmt"
"os"
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/libpod/define"
"github.com/spf13/cobra"
"go.podman.io/common/pkg/completion"
)
@ -27,7 +23,7 @@ var (
Args: validate.NoArgs,
Short: "Migrate lock numbers",
Long: renumberDescription,
Run: renumber,
RunE: renumber,
ValidArgsFunction: completion.AutocompleteNone,
}
)
@ -39,12 +35,6 @@ func init() {
})
}
func renumber(cmd *cobra.Command, args []string) {
if err := registry.ContainerEngine().Renumber(registry.Context()); err != nil {
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)
func renumber(cmd *cobra.Command, args []string) error {
return registry.ContainerEngine().Renumber(registry.Context())
}