From 53e8fc983d8d489aaeb8c7e982052f9e3dcc4b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Thu, 22 Aug 2024 18:37:02 +0200 Subject: [PATCH] chore: add support for nilerr (#4061) --- .golangci.yml | 1 + internal/namespaces/config/commands.go | 2 +- internal/namespaces/instance/v1/custom_server_rdp.go | 2 +- internal/namespaces/instance/v1/custom_ssh_config.go | 2 +- internal/namespaces/object/v1/s3configfile.go | 2 +- internal/namespaces/rdb/v1/custom_instance.go | 2 +- internal/namespaces/registry/v1/custom_image.go | 2 +- internal/namespaces/registry/v1/custom_tag.go | 3 +++ 8 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1b26d35e5e..23b5da0e72 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,7 @@ linters: - misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true] - musttag # enforce field tags in (un)marshaled structs [fast: false, auto-fix: false] - nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false] + - nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false] - nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false] - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false] - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [fast: false, auto-fix: false] diff --git a/internal/namespaces/config/commands.go b/internal/namespaces/config/commands.go index b95f7f3101..c6be3450a0 100644 --- a/internal/namespaces/config/commands.go +++ b/internal/namespaces/config/commands.go @@ -541,7 +541,7 @@ func configDestroyCommand() *core.Command { configPath := core.ExtractConfigPath(ctx) err := os.Remove(configPath) if err != nil { - return err, nil + return nil, err } return &core.SuccessResult{ Message: "successfully destroy config", diff --git a/internal/namespaces/instance/v1/custom_server_rdp.go b/internal/namespaces/instance/v1/custom_server_rdp.go index 4b80b454e2..daf1910ee6 100644 --- a/internal/namespaces/instance/v1/custom_server_rdp.go +++ b/internal/namespaces/instance/v1/custom_server_rdp.go @@ -153,7 +153,7 @@ func instanceServerGetRdpPasswordRun(ctx context.Context, argsI interface{}) (i func parsePrivateKey(ctx context.Context, key []byte) (any, error) { privateKey, err := ssh.ParseRawPrivateKey(key) if err == nil { - return privateKey, err + return privateKey, nil } // Key may need a passphrase missingPassphraseError := &ssh.PassphraseMissingError{} diff --git a/internal/namespaces/instance/v1/custom_ssh_config.go b/internal/namespaces/instance/v1/custom_ssh_config.go index 128da44b5b..ae17ac93b7 100644 --- a/internal/namespaces/instance/v1/custom_ssh_config.go +++ b/internal/namespaces/instance/v1/custom_ssh_config.go @@ -139,7 +139,7 @@ Do you want the include statement to be added at the beginning of your file ?`, logger.Warningf("Failed to prompt, skipping include\n") return &core.SuccessResult{ Message: configFileGeneratedMessage + " " + configFilePath, - }, nil + }, err } if shouldIncludeConfig { diff --git a/internal/namespaces/object/v1/s3configfile.go b/internal/namespaces/object/v1/s3configfile.go index fbed747a44..0baf1226bf 100644 --- a/internal/namespaces/object/v1/s3configfile.go +++ b/internal/namespaces/object/v1/s3configfile.go @@ -156,7 +156,7 @@ func (c s3config) getConfigFile(tool s3tool) (core.RawResult, error) { } res, err := json.Marshal(m) if err != nil { - return nil, nil + return nil, err } return append(res, '\n'), nil default: diff --git a/internal/namespaces/rdb/v1/custom_instance.go b/internal/namespaces/rdb/v1/custom_instance.go index 407ded2cb4..6b64061fee 100644 --- a/internal/namespaces/rdb/v1/custom_instance.go +++ b/internal/namespaces/rdb/v1/custom_instance.go @@ -342,7 +342,7 @@ func instanceGetBuilder(c *core.Command) *core.Command { InstanceID: args.InstanceID, }, scw.WithAllPages()) if err != nil { - return res, nil + return nil, err } return struct { diff --git a/internal/namespaces/registry/v1/custom_image.go b/internal/namespaces/registry/v1/custom_image.go index ed385e8d08..3d86e96a8b 100644 --- a/internal/namespaces/registry/v1/custom_image.go +++ b/internal/namespaces/registry/v1/custom_image.go @@ -46,7 +46,7 @@ func imageGetBuilder(c *core.Command) *core.Command { NamespaceID: image.NamespaceID, }) if err != nil { - return getImageResp, nil + return getImageResp, err } res := customImage{ diff --git a/internal/namespaces/registry/v1/custom_tag.go b/internal/namespaces/registry/v1/custom_tag.go index acd4d0eb8c..f9ac43052a 100644 --- a/internal/namespaces/registry/v1/custom_tag.go +++ b/internal/namespaces/registry/v1/custom_tag.go @@ -8,6 +8,7 @@ import ( "github.com/scaleway/scaleway-cli/v2/internal/core" "github.com/scaleway/scaleway-cli/v2/internal/human" "github.com/scaleway/scaleway-sdk-go/api/registry/v1" + "github.com/scaleway/scaleway-sdk-go/logger" ) // @@ -44,6 +45,7 @@ func tagGetBuilder(c *core.Command) *core.Command { ImageID: tag.ImageID, }) if err != nil { + logger.Warningf("cannot get image %s %s", tag.ImageID, err) return getTagResp, nil } @@ -51,6 +53,7 @@ func tagGetBuilder(c *core.Command) *core.Command { NamespaceID: image.NamespaceID, }) if err != nil { + logger.Warningf("cannot get namespace %s %s", image.NamespaceID, err) return getTagResp, nil }