Skip to content

Commit b3ada6c

Browse files
Merge pull request #27178 from osamakader/fix-system-commands-error-handling
cmd/podman/system: fix error handling in renumber and migrate commands
2 parents e57a7f3 + b5de5ef commit b3ada6c

File tree

2 files changed

+6
-27
lines changed

2 files changed

+6
-27
lines changed

cmd/podman/system/migrate.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
package system
44

55
import (
6-
"fmt"
7-
"os"
8-
96
"github.com/containers/podman/v5/cmd/podman/registry"
107
"github.com/containers/podman/v5/cmd/podman/validate"
11-
"github.com/containers/podman/v5/libpod/define"
128
"github.com/containers/podman/v5/pkg/domain/entities"
139
"github.com/spf13/cobra"
1410
"go.podman.io/common/pkg/completion"
@@ -30,7 +26,7 @@ var (
3026
Args: validate.NoArgs,
3127
Short: "Migrate containers",
3228
Long: migrateDescription,
33-
Run: migrate,
29+
RunE: migrate,
3430
ValidArgsFunction: completion.AutocompleteNone,
3531
}
3632
)
@@ -52,13 +48,6 @@ func init() {
5248
_ = migrateCommand.RegisterFlagCompletionFunc(newRuntimeFlagName, completion.AutocompleteNone)
5349
}
5450

55-
func migrate(cmd *cobra.Command, args []string) {
56-
if err := registry.ContainerEngine().Migrate(registry.Context(), migrateOptions); err != nil {
57-
fmt.Println(err)
58-
59-
// FIXME change this to return the error like other commands
60-
// defer will never run on os.Exit()
61-
os.Exit(define.ExecErrorCodeGeneric)
62-
}
63-
os.Exit(0)
51+
func migrate(cmd *cobra.Command, args []string) error {
52+
return registry.ContainerEngine().Migrate(registry.Context(), migrateOptions)
6453
}

cmd/podman/system/renumber.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
package system
44

55
import (
6-
"fmt"
7-
"os"
8-
96
"github.com/containers/podman/v5/cmd/podman/registry"
107
"github.com/containers/podman/v5/cmd/podman/validate"
11-
"github.com/containers/podman/v5/libpod/define"
128
"github.com/spf13/cobra"
139
"go.podman.io/common/pkg/completion"
1410
)
@@ -27,7 +23,7 @@ var (
2723
Args: validate.NoArgs,
2824
Short: "Migrate lock numbers",
2925
Long: renumberDescription,
30-
Run: renumber,
26+
RunE: renumber,
3127
ValidArgsFunction: completion.AutocompleteNone,
3228
}
3329
)
@@ -39,12 +35,6 @@ func init() {
3935
})
4036
}
4137

42-
func renumber(cmd *cobra.Command, args []string) {
43-
if err := registry.ContainerEngine().Renumber(registry.Context()); err != nil {
44-
fmt.Println(err)
45-
// FIXME change this to return the error like other commands
46-
// defer will never run on os.Exit()
47-
os.Exit(define.ExecErrorCodeGeneric)
48-
}
49-
os.Exit(0)
38+
func renumber(cmd *cobra.Command, args []string) error {
39+
return registry.ContainerEngine().Renumber(registry.Context())
5040
}

0 commit comments

Comments
 (0)