From ea6fdae4b97eea5e6ce796c59c9f17ade5f9bd0f Mon Sep 17 00:00:00 2001 From: Yacine Fodil <105779815+yfodil@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:40:09 +0100 Subject: [PATCH] feat(lb): improve backend help in case healthcheck is missing (#2689) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rémy Léone --- internal/namespaces/lb/v1/custom_backend.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/namespaces/lb/v1/custom_backend.go b/internal/namespaces/lb/v1/custom_backend.go index fe5fc7abcd..65ca8c6738 100644 --- a/internal/namespaces/lb/v1/custom_backend.go +++ b/internal/namespaces/lb/v1/custom_backend.go @@ -2,6 +2,7 @@ package lb import ( "context" + "errors" "fmt" "reflect" "strings" @@ -12,6 +13,7 @@ import ( "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1" "github.com/scaleway/scaleway-sdk-go/api/instance/v1" "github.com/scaleway/scaleway-sdk-go/api/lb/v1" + "github.com/scaleway/scaleway-sdk-go/scw" ) var ( @@ -781,6 +783,21 @@ func interceptBackend() core.CommandInterceptor { res, err := runner(ctx, argsI) if err != nil { + var invalidArgErr *scw.InvalidArgumentsError + if errors.As(err, &invalidArgErr) { + for _, detail := range invalidArgErr.Details { + switch detail.ArgumentName { + case "Port": + return nil, &core.CliError{ + Err: fmt.Errorf("missing or invalid 'health-check.port' argument"), + } + case "CheckMaxRetries": + return nil, &core.CliError{ + Err: fmt.Errorf("missing or invalid 'health-check.check-max-retries' argument"), + } + } + } + } return nil, err }