run modernize -fix ./...

Since I use go 1.26 the go fix does not have all the rules built in,
there are newer ones in modernize so run the explicitly to fix more code
for go 1.26.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
(cherry picked from commit 6c6eac3a5c)
NOTE: not a clean cherry-pick.
Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
This commit is contained in:
Paul Holzinger 2026-09-03 19:14:03 +02:00 • committed by Lokesh Mandvekar
parent f63f6228b6
commit 24ef8bb16e
No known key found for this signature in database
GPG key ID: 1C1EDD7CC7C3A0DD
18 changed files with 30 additions and 40 deletions

View file

@ -101,8 +101,7 @@ func main() {
} else {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
var ee *exec.ExitError
if errors.As(err, &ee) {
if ee, ok := errors.AsType[*exec.ExitError](err); ok {
if w, ok := ee.Sys().(syscall.WaitStatus); ok {
exitCode = w.ExitStatus()
}

View file

@ -219,7 +219,7 @@ func composeProviderExec(args []string, stdout io.Writer, stderr io.Writer, warn
if err := cmd.Run(); err != nil {
// Make sure podman returns with the same exit code as the compose provider.
if exitErr, isExit := err.(*exec.ExitError); isExit {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
registry.SetExitCode(exitErr.ExitCode())
}
// Format the error to make it explicit that error did not come

View file

@ -213,13 +213,12 @@ func initMachine(cmd *cobra.Command, args []string) error {
}
// Check if machine already exists
var errNotExists *define.ErrVMDoesNotExist
_, _, err := shim.VMExists(initOpts.Name)
// if nil, means we found a vm and need to reject it by name
if err == nil {
return &define.ErrVMAlreadyExists{Name: initOpts.Name}
}
if !errors.As(err, &errNotExists) {
if _, ok := errors.AsType[*define.ErrVMDoesNotExist](err); !ok {
return err
}

View file

@ -60,8 +60,7 @@ func ssh(_ *cobra.Command, args []string) error {
// it implies podman cannot read its machine files, which is bad
mc, vmProvider, err = shim.VMExists(args[0])
if err != nil {
var vmNotExistsErr *define.ErrVMDoesNotExist
if !errors.As(err, &vmNotExistsErr) {
if _, ok := errors.AsType[*define.ErrVMDoesNotExist](err); !ok {
return err
}
sshOpts.Args = append(sshOpts.Args, args[0])

View file

@ -60,8 +60,7 @@ func HandleOSExecError(err error) error {
if err == nil {
return nil
}
var exitError *exec.ExitError
if errors.As(err, &exitError) {
if exitError, ok := errors.AsType[*exec.ExitError](err); ok {
// the user command inside the unshare/ssh env has failed
// we set the exit code, do not return the error to the user
// otherwise "exit status X" will be printed

View file

@ -673,8 +673,7 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.
// isRetryable returns whether the error was caused by a blocked syscall or the
// specified operation on a non blocking file descriptor wasn't ready for completion.
func isRetryable(err error) bool {
var errno syscall.Errno
if errors.As(err, &errno) {
if errno, ok := errors.AsType[syscall.Errno](err); ok {
return errno == syscall.EINTR || errno == syscall.EAGAIN
}
return false

View file

@ -49,8 +49,7 @@ func Auth(w http.ResponseWriter, r *http.Request) {
} else {
var msg string
var unauthErr DockerClient.ErrUnauthorizedForCredentials
if errors.As(err, &unauthErr) {
if _, ok := errors.AsType[DockerClient.ErrUnauthorizedForCredentials](err); ok {
msg = "401 Unauthorized"
} else {
msg = err.Error()

View file

@ -4,6 +4,7 @@ package handlers
import (
"encoding/json"
"errors"
"reflect"
"strconv"
"strings"
@ -128,7 +129,7 @@ func convertTimeString(query string) reflect.Value {
return reflect.ValueOf(t)
}
if _, isParseError := err.(*time.ParseError); isParseError {
if _, ok := errors.AsType[*time.ParseError](err); ok {
// Try next format
continue
} else {

View file

@ -390,8 +390,7 @@ func PushArtifact(w http.ResponseWriter, r *http.Request) {
}
}
var notFoundErr layout.ImageNotFoundError
if errors.As(err, &notFoundErr) {
if notFoundErr, ok := errors.AsType[layout.ImageNotFoundError](err); ok {
utils.ArtifactNotFound(w, name, notFoundErr)
return
}

View file

@ -133,7 +133,7 @@ func GetInternalServerError(err error) *BuildError {
}
func ProcessBuildError(w http.ResponseWriter, err error) {
if buildErr, ok := err.(*BuildError); ok {
if buildErr, ok := errors.AsType[*BuildError](err); ok {
Error(w, buildErr.code, buildErr.err)
return
}

View file

@ -55,14 +55,13 @@ func (h *APIResponse) ProcessWithError(unmarshalInto any, unmarshalErrorInto any
}
func CheckResponseCode(inError error) (int, error) {
switch e := inError.(type) {
case *errorhandling.ErrorModel:
return e.Code(), nil
case *errorhandling.PodConflictErrorModel:
return e.Code(), nil
default:
return -1, errors.New("is not type ErrorModel")
if errModel, ok := errors.AsType[*errorhandling.ErrorModel](inError); ok {
return errModel.Code(), nil
}
if podConflictModel, ok := errors.AsType[*errorhandling.PodConflictErrorModel](inError); ok {
return podConflictModel.Code(), nil
}
return -1, errors.New("is not type ErrorModel")
}
type APIVersionError struct {

View file

@ -12,7 +12,7 @@ import (
)
func IsSimpleType(f reflect.Value) bool {
if _, ok := f.Interface().(fmt.Stringer); ok {
if _, ok := reflect.TypeAssert[fmt.Stringer](f); ok {
return true
}
@ -25,7 +25,7 @@ func IsSimpleType(f reflect.Value) bool {
}
func SimpleTypeToParam(f reflect.Value) string {
if s, ok := f.Interface().(fmt.Stringer); ok {
if s, ok := reflect.TypeAssert[fmt.Stringer](f); ok {
return s.String()
}

View file

@ -118,8 +118,7 @@ func (ir *ImageEngine) ArtifactAdd(_ context.Context, name string, artifactBlob
if err == nil {
continue
}
var errModel *errorhandling.ErrorModel
if errors.As(err, &errModel) {
if errModel, ok := errors.AsType[*errorhandling.ErrorModel](err); ok {
switch errModel.ResponseCode {
case http.StatusNotFound, http.StatusMethodNotAllowed:
default:

View file

@ -225,8 +225,7 @@ func (ir *ImageEngine) Load(_ context.Context, opts entities.ImageLoadOptions) (
if err == nil {
return report, nil
}
var errModel *errorhandling.ErrorModel
if errors.As(err, &errModel) {
if errModel, ok := errors.AsType[*errorhandling.ErrorModel](err); ok {
switch errModel.ResponseCode {
case http.StatusNotFound, http.StatusMethodNotAllowed:
default:
@ -420,8 +419,7 @@ func (ir *ImageEngine) Build(_ context.Context, containerFiles []string, opts en
}
logrus.Debugf("BuildLocal failed: %v", err)
var errModel *errorhandling.ErrorModel
if errors.As(err, &errModel) {
if errModel, ok := errors.AsType[*errorhandling.ErrorModel](err); ok {
switch errModel.ResponseCode {
case http.StatusNotFound, http.StatusMethodNotAllowed:
default:

View file

@ -333,7 +333,7 @@ func launchElevate(operation string) error {
}
err := winutil.RelaunchElevatedWait()
if err != nil {
if eerr, ok := err.(*winutil.ExitCodeError); ok {
if eerr, ok := errors.AsType[*winutil.ExitCodeError](err); ok {
if eerr.Code == ErrorSuccessRebootRequired {
fmt.Println("Reboot is required to continue installation, please reboot at your convenience")
return define.ErrRelaunchSucceeded
@ -374,7 +374,7 @@ func isMsiError(err error) bool {
return false
}
if eerr, ok := err.(*exec.ExitError); ok {
if eerr, ok := errors.AsType[*exec.ExitError](err); ok {
switch eerr.ExitCode() {
case 0:
fallthrough

View file

@ -153,7 +153,7 @@ func stopUserModeNetworking(mc *vmconfigs.MachineConfig) error {
err = wslPipe(stopUserModeNet, userModeDist, "bash")
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
switch exitErr.ExitCode() {
case 2:
err = fmt.Errorf("startup state was missing")
@ -184,7 +184,7 @@ func launchUserModeNetDist(exeFile string) error {
if err := wslPipe(cmdStr, userModeDist, "bash"); err != nil {
_ = terminateDist(userModeDist)
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr, ok := errors.AsType[*exec.ExitError](err); ok {
switch exitErr.ExitCode() {
case 2:
return fmt.Errorf("another user-mode network is running, only one can be used at a time: shut down all machines and run wsl --shutdown if this is unexpected")

View file

@ -67,8 +67,7 @@ func parseWSLStatus() wslStatus {
var outputErr error
status, outputErr = matchOutputLine(out)
err = cmd.Wait()
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if _, ok := errors.AsType[*exec.ExitError](err); ok {
// If `wsl --status` returns an exit error
// we assume that WSL isn't installed and
// override whatever was returned by

View file

@ -1122,7 +1122,7 @@ func SkipIfSystemdNotRunning(reason string) {
cmd := exec.Command("systemctl", "list-units")
err := cmd.Run()
if err != nil {
if _, ok := err.(*exec.Error); ok {
if _, ok := errors.AsType[*exec.Error](err); ok {
Skip("[notSystemd]: not running " + reason)
}
Expect(err).ToNot(HaveOccurred())
@ -1366,7 +1366,8 @@ func (p *PodmanTestIntegration) makeOptions(args []string, options PodmanExecOpt
eventsType = "none"
}
podmanOptions = append(podmanOptions,
podmanOptions = append(
podmanOptions,
"--root", p.Root,
"--runroot", p.RunRoot,
"--runtime", p.OCIRuntime,