mirror of
https://github.com/containers/podman.git
synced 2025-10-19 12:12:36 +08:00
cmd/podman/system: fix error handling in renumber and migrate commands
- Change function signatures to return error instead of calling os.Exit() - Update cobra commands to use RunE instead of Run for proper error handling - Remove unused imports (fmt, os, define) - Remove FIXME comments about error handling inconsistency This allows defer statements to run properly and improves testability. Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
This commit is contained in:
@ -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)
|
|
||||||
}
|
}
|
||||||
|
@ -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)
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user