Skip to content

Commit 5834929

Browse files
vhvb1989Copilot
andcommitted
fix: use typed sentinel errors in sub-filter Run() methods
Replace bare fmt.Errorf calls with %w-wrapped typed sentinels to satisfy Test_RunMethodsNoBareErrors CI check. Added ErrInteractiveRequired, ErrNoSubscriptionsFound, ErrNoTenantsFound, ErrNoFilterExists to internal/errors.go. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 085bb43 commit 5834929

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

cli/azd/cmd/config_sub_filter.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"strings"
1313

1414
"github.com/azure/azure-dev/cli/azd/cmd/actions"
15+
"github.com/azure/azure-dev/cli/azd/internal"
1516
"github.com/azure/azure-dev/cli/azd/pkg/account"
1617
"github.com/azure/azure-dev/cli/azd/pkg/config"
1718
"github.com/azure/azure-dev/cli/azd/pkg/input"
@@ -83,8 +84,8 @@ func (a *subFilterSetAction) Run(
8384
) (*actions.ActionResult, error) {
8485
if a.console.IsNoPromptMode() {
8586
return nil, fmt.Errorf(
86-
"subscription filter set requires interactive mode" +
87-
" (cannot run with --no-prompt)",
87+
"subscription filter set requires interactive mode (cannot run with --no-prompt): %w",
88+
internal.ErrInteractiveRequired,
8889
)
8990
}
9091

@@ -105,7 +106,10 @@ func (a *subFilterSetAction) Run(
105106
}
106107

107108
if len(subscriptions) == 0 {
108-
return nil, fmt.Errorf("no subscriptions found")
109+
return nil, fmt.Errorf(
110+
"no subscriptions found: %w",
111+
internal.ErrNoSubscriptionsFound,
112+
)
109113
}
110114

111115
// Resolve tenant
@@ -122,7 +126,8 @@ func (a *subFilterSetAction) Run(
122126
)
123127
if len(tenantSubs) == 0 {
124128
return nil, fmt.Errorf(
125-
"no subscriptions found for tenant %s", tenantId,
129+
"no subscriptions found for tenant %s: %w",
130+
tenantId, internal.ErrNoSubscriptionsFound,
126131
)
127132
}
128133

@@ -280,8 +285,8 @@ func (a *subFilterRemoveAction) Run(
280285
) (*actions.ActionResult, error) {
281286
if a.console.IsNoPromptMode() {
282287
return nil, fmt.Errorf(
283-
"subscription filter remove requires interactive mode" +
284-
" (cannot run with --no-prompt)",
288+
"subscription filter remove requires interactive mode (cannot run with --no-prompt): %w",
289+
internal.ErrInteractiveRequired,
285290
)
286291
}
287292

@@ -302,7 +307,10 @@ func (a *subFilterRemoveAction) Run(
302307
}
303308

304309
if len(subscriptions) == 0 {
305-
return nil, fmt.Errorf("no subscriptions found")
310+
return nil, fmt.Errorf(
311+
"no subscriptions found: %w",
312+
internal.ErrNoSubscriptionsFound,
313+
)
306314
}
307315

308316
// Resolve tenant
@@ -401,7 +409,9 @@ func resolveTenantForFilter(
401409
// API call when only a single tenant exists.
402410
tenants := prompt.ExtractUniqueTenants(subscriptions, nil)
403411
if len(tenants) == 0 {
404-
return "", "", fmt.Errorf("no tenants found")
412+
return "", "", fmt.Errorf(
413+
"no tenants found: %w", internal.ErrNoTenantsFound,
414+
)
405415
}
406416

407417
if len(tenants) == 1 {

cli/azd/internal/errors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ var (
123123
ErrToolUpgradeFailed = errors.New("tool upgrade did not succeed")
124124
)
125125

126+
// Subscription filter errors
127+
var (
128+
ErrInteractiveRequired = errors.New("interactive mode required")
129+
ErrNoSubscriptionsFound = errors.New("no subscriptions found")
130+
ErrNoTenantsFound = errors.New("no tenants found")
131+
ErrNoFilterExists = errors.New("no saved filter exists")
132+
)
133+
126134
// ExitCodeError wraps an error with a specific process exit code.
127135
// When returned from an action, main.go uses the exit code instead of the
128136
// default exit code 1. This is used by `azd exec` to propagate the child

0 commit comments

Comments
 (0)