From f9dcc66bb533f2917316c33d13f107ceeeca00a2 Mon Sep 17 00:00:00 2001 From: Dawid Pogorzelski Date: Thu, 13 Jan 2022 23:45:56 +0100 Subject: [PATCH] Fix a bug where an empty target would return no results --- pkg/speedrun/cloud/instance.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/speedrun/cloud/instance.go b/pkg/speedrun/cloud/instance.go index 75b122a..de8e188 100644 --- a/pkg/speedrun/cloud/instance.go +++ b/pkg/speedrun/cloud/instance.go @@ -6,6 +6,7 @@ import ( "github.com/antonmedv/expr" "github.com/apex/log" + "github.com/pkg/errors" "github.com/speedrunsh/speedrun/pkg/common/cryptoutil" "github.com/spf13/viper" ) @@ -40,14 +41,15 @@ func GetInstances(target string) ([]Instance, error) { } subset, err := filter(instances, target) - if err != nil { - return nil, err - } - if len(subset) == 0 { return nil, fmt.Errorf("no instances found") } + if err != nil { + err = errors.Wrap(err, "could not filter instance list") + return nil, err + } + return subset, nil } @@ -67,6 +69,10 @@ func SetupTLS() (*tls.Config, error) { } func filter(instnces []Instance, target string) ([]Instance, error) { + if target == "" { + return instnces, nil + } + var subset []Instance program, err := expr.Compile(target, expr.Env(Instance{}), expr.AsBool())