From ee77888a1c7c084cd9fd9aed0734b8886fbd0556 Mon Sep 17 00:00:00 2001 From: ota42y Date: Thu, 4 Mar 2021 17:54:22 +0900 Subject: [PATCH 1/4] fix: add subnets error messages --- internal/pkg/task/env_runner.go | 6 ++++-- internal/pkg/task/env_runner_test.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/pkg/task/env_runner.go b/internal/pkg/task/env_runner.go index aada4f915ca..f0abb3e3f57 100644 --- a/internal/pkg/task/env_runner.go +++ b/internal/pkg/task/env_runner.go @@ -12,7 +12,7 @@ import ( ) const ( - fmtErrPublicSubnetsFromEnv = "get public subnet IDs from environment %s: %w" + fmtErrPublicSubnetsFromEnv = "get public subnet IDs from environment %s: %w " fmtErrSecurityGroupsFromEnv = "get security groups from environment %s: %w" envSecurityGroupCFNLogicalIDTagKey = "aws:cloudformation:logical-id" @@ -21,6 +21,8 @@ const ( // Names for tag filters var ( + fmtErrNoSubnetFoundInEnv = fmt.Sprintf("no subnets found from environment %s (need %s and %s tag?)", "%s", deploy.AppTagKey, deploy.EnvTagKey) + tagFilterNameForApp = fmt.Sprintf(ec2.TagFilterName, deploy.AppTagKey) tagFilterNameForEnv = fmt.Sprintf(ec2.TagFilterName, deploy.EnvTagKey) ) @@ -60,7 +62,7 @@ func (r *EnvRunner) Run() ([]*Task, error) { return nil, fmt.Errorf(fmtErrPublicSubnetsFromEnv, r.Env, err) } if len(subnets) == 0 { - return nil, errNoSubnetFound + return nil, fmt.Errorf(fmtErrNoSubnetFoundInEnv, r.Env) } // Use only environment security group https://github.com/aws/copilot-cli/issues/1882. diff --git a/internal/pkg/task/env_runner_test.go b/internal/pkg/task/env_runner_test.go index 3d410d1b403..45f3eaeeeef 100644 --- a/internal/pkg/task/env_runner_test.go +++ b/internal/pkg/task/env_runner_test.go @@ -83,7 +83,7 @@ func TestEnvRunner_Run(t *testing.T) { m.EXPECT().SecurityGroups(gomock.Any()).AnyTimes() }, mockStarter: mockStarterNotRun, - wantedError: errNoSubnetFound, + wantedError: fmt.Errorf(fmtErrNoSubnetFoundInEnv, inEnv), }, "failed to get security groups": { MockClusterGetter: MockClusterGetter, From 854622a0e037ef7230f3a1c7f16c68da87582b75 Mon Sep 17 00:00:00 2001 From: ota42y Date: Tue, 9 Mar 2021 19:24:25 +0900 Subject: [PATCH 2/4] catch error in cli package and show warning --- internal/pkg/cli/task_run.go | 4 ++++ internal/pkg/task/config_runner.go | 2 +- internal/pkg/task/env_runner.go | 6 ++---- internal/pkg/task/env_runner_test.go | 2 +- internal/pkg/task/errors.go | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/pkg/cli/task_run.go b/internal/pkg/cli/task_run.go index 93c31f7466d..08c2b8a70d5 100644 --- a/internal/pkg/cli/task_run.go +++ b/internal/pkg/cli/task_run.go @@ -438,6 +438,10 @@ func (o *runTaskOpts) runTask() ([]*task.Task, error) { o.spinner.Start(fmt.Sprintf("Waiting for %s to be running for %s.", english.Plural(o.count, "task", ""), o.groupName)) tasks, err := o.runner.Run() if err != nil { + if err == task.ErrNoSubnetFound { + log.Warningf("Subnets need to be tagged with %s and %s. Are your subnets tagged?\n", deploy.AppTagKey, deploy.EnvTagKey) + } + o.spinner.Stop(log.Serrorf("Failed to run %s.\n\n", o.groupName)) return nil, fmt.Errorf("run task %s: %w", o.groupName, err) } diff --git a/internal/pkg/task/config_runner.go b/internal/pkg/task/config_runner.go index bd75f7242f1..af94671cdae 100644 --- a/internal/pkg/task/config_runner.go +++ b/internal/pkg/task/config_runner.go @@ -53,7 +53,7 @@ func (r *NetworkConfigRunner) Run() ([]*Task, error) { return nil, fmt.Errorf(fmtErrDefaultSubnets, err) } if len(subnets) == 0 { - return nil, errNoSubnetFound + return nil, ErrNoSubnetFound } r.Subnets = subnets diff --git a/internal/pkg/task/env_runner.go b/internal/pkg/task/env_runner.go index f0abb3e3f57..39034d7c6bb 100644 --- a/internal/pkg/task/env_runner.go +++ b/internal/pkg/task/env_runner.go @@ -12,7 +12,7 @@ import ( ) const ( - fmtErrPublicSubnetsFromEnv = "get public subnet IDs from environment %s: %w " + fmtErrPublicSubnetsFromEnv = "get public subnet IDs from environment %s: %w" fmtErrSecurityGroupsFromEnv = "get security groups from environment %s: %w" envSecurityGroupCFNLogicalIDTagKey = "aws:cloudformation:logical-id" @@ -21,8 +21,6 @@ const ( // Names for tag filters var ( - fmtErrNoSubnetFoundInEnv = fmt.Sprintf("no subnets found from environment %s (need %s and %s tag?)", "%s", deploy.AppTagKey, deploy.EnvTagKey) - tagFilterNameForApp = fmt.Sprintf(ec2.TagFilterName, deploy.AppTagKey) tagFilterNameForEnv = fmt.Sprintf(ec2.TagFilterName, deploy.EnvTagKey) ) @@ -62,7 +60,7 @@ func (r *EnvRunner) Run() ([]*Task, error) { return nil, fmt.Errorf(fmtErrPublicSubnetsFromEnv, r.Env, err) } if len(subnets) == 0 { - return nil, fmt.Errorf(fmtErrNoSubnetFoundInEnv, r.Env) + return nil, ErrNoSubnetFound } // Use only environment security group https://github.com/aws/copilot-cli/issues/1882. diff --git a/internal/pkg/task/env_runner_test.go b/internal/pkg/task/env_runner_test.go index 45f3eaeeeef..a31ecdc8898 100644 --- a/internal/pkg/task/env_runner_test.go +++ b/internal/pkg/task/env_runner_test.go @@ -83,7 +83,7 @@ func TestEnvRunner_Run(t *testing.T) { m.EXPECT().SecurityGroups(gomock.Any()).AnyTimes() }, mockStarter: mockStarterNotRun, - wantedError: fmt.Errorf(fmtErrNoSubnetFoundInEnv, inEnv), + wantedError: ErrNoSubnetFound, }, "failed to get security groups": { MockClusterGetter: MockClusterGetter, diff --git a/internal/pkg/task/errors.go b/internal/pkg/task/errors.go index 3269f4da3fb..4f079460557 100644 --- a/internal/pkg/task/errors.go +++ b/internal/pkg/task/errors.go @@ -9,7 +9,7 @@ import ( ) var ( - errNoSubnetFound = errors.New("no subnets found") + ErrNoSubnetFound = errors.New("no subnets found") errVPCGetterNil = errors.New("vpc getter is not set") errClusterGetterNil = errors.New("cluster getter is not set") From 01da17ce861b44b2aaba1437b38a9f2fab8a45bf Mon Sep 17 00:00:00 2001 From: ota42y Date: Wed, 10 Mar 2021 13:12:43 +0900 Subject: [PATCH 3/4] Update internal/pkg/cli/task_run.go Co-authored-by: Efe Karakus --- internal/pkg/cli/task_run.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/pkg/cli/task_run.go b/internal/pkg/cli/task_run.go index 08c2b8a70d5..6e9d72352ff 100644 --- a/internal/pkg/cli/task_run.go +++ b/internal/pkg/cli/task_run.go @@ -438,7 +438,7 @@ func (o *runTaskOpts) runTask() ([]*task.Task, error) { o.spinner.Start(fmt.Sprintf("Waiting for %s to be running for %s.", english.Plural(o.count, "task", ""), o.groupName)) tasks, err := o.runner.Run() if err != nil { - if err == task.ErrNoSubnetFound { + if errors.Is(err, task.ErrNoSubnetFound) { log.Warningf("Subnets need to be tagged with %s and %s. Are your subnets tagged?\n", deploy.AppTagKey, deploy.EnvTagKey) } From 7a169bad62fde13b1ebdabd630beb71687779788 Mon Sep 17 00:00:00 2001 From: ota42y Date: Wed, 10 Mar 2021 13:17:25 +0900 Subject: [PATCH 4/4] add top level comment --- internal/pkg/task/errors.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/pkg/task/errors.go b/internal/pkg/task/errors.go index 4f079460557..fc8d84db4df 100644 --- a/internal/pkg/task/errors.go +++ b/internal/pkg/task/errors.go @@ -8,6 +8,7 @@ import ( "fmt" ) +// Errors returned while trying to run a task. var ( ErrNoSubnetFound = errors.New("no subnets found")