Improve error message when no subscriptions are found#7046
Improve error message when no subscriptions are found#7046hemarina wants to merge 1 commit intoAzure:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the “no subscriptions found” experience by adding clearer, actionable guidance (especially for multi-tenant sign-in and MFA scenarios) via both the interactive prompt error text and the centralized error-suggestion pipeline.
Changes:
- Add a new
error_suggestions.yamlrule for matching “no subscriptions found” and providing next steps + docs link. - Update
PromptSubscription’s “no subscriptions found” error text to mention--tenant-idfor multi-tenant scenarios. - Add a pipeline test to verify the new YAML rule matches and returns the expected message/suggestion.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/azd/resources/error_suggestions.yaml | Adds a new pattern-based rule for “no subscriptions found” with tenant/MFA guidance and a reference link. |
| cli/azd/pkg/prompt/prompter.go | Extends the subscription prompt error message with tenant-id guidance. |
| cli/azd/pkg/errorhandler/pipeline_test.go | Adds a test ensuring the new YAML rule is picked up and produces the expected output. |
Comments suppressed due to low confidence (1)
cli/azd/resources/error_suggestions.yaml:405
- This is a text-pattern-only rule (no errorType/properties), but it’s placed before the “Text Pattern Rules — Specific patterns first” section header. Since rules are ordered and the file is organized by rule type, consider moving this rule into the text-pattern section to keep the YAML structure consistent and easier to maintain.
# ============================================================================
# Subscription Errors
# ============================================================================
- patterns:
- "no subscriptions found"
message: "No Azure subscriptions were found for your account."
suggestion: >
Ensure you have an active subscription at https://portal.azure.com.
If you have multiple tenants, run 'azd auth login --tenant-id <tenant-id>'
to sign in to a specific tenant. Multi-factor authentication (MFA) may prevent
automatic access to all tenants — visit the Azure portal and switch to each tenant
to refresh your MFA sessions, then retry 'azd auth login'.
links:
- url: "https://learn.microsoft.com/azure/developer/azure-developer-cli/reference#azd-auth-login"
title: "azd auth login reference"
# ============================================================================
# Text Pattern Rules — Specific patterns first
# These are fallbacks for errors without typed Go structs.
# ============================================================================
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wbreza
left a comment
There was a problem hiding this comment.
Code Review
Great work addressing issue #6419 — the MFA and multi-tenant scenario guidance is exactly the kind of actionable error messaging that improves the developer experience. The error suggestion YAML rule is well-structured and includes a helpful documentation link. 🎉
✅ What Looks Good
- Correctly leverages the
error_suggestions.yamlpipeline for error enrichment - YAML rule structure (patterns, message, suggestion, links) is consistent with existing rules
- MFA scenario guidance is thoughtful and addresses a real user pain point
- Test validates pattern matching through the standard pipeline approach
Findings Summary
| Priority | Count |
|---|---|
| High | 2 |
| Medium | 3 |
| Low | 1 |
| Total | 6 |
It would be great to establish a consistent model for custom error messages going forward — the inline error text in the Go code should stay minimal, and the YAML pipeline should own the enriched user-facing guidance. This keeps our error handling patterns clean and maintainable across the project.
| Ensure you have a subscription by visiting %s and search for Subscriptions in the search bar. | ||
| Once you have a subscription, run 'azd auth login' again to reload subscriptions.`, | ||
| Once you have a subscription, run 'azd auth login' again to reload subscriptions. | ||
| If you have multiple tenants, run 'azd auth login --tenant-id <tenant-id>' to specify your tenant.`, |
There was a problem hiding this comment.
[High] Dual error paths with overlapping guidance (DRY violation)
The --tenant-id multi-tenant guidance now exists in both this inline error message AND the new error_suggestions.yaml rule. When the error handler middleware processes this error, the user will see the original error (with tenant-id advice) plus the YAML overlay (with the same tenant-id advice), creating redundant guidance.
Consider removing this line and letting the YAML rule own the enriched multi-tenant guidance — that aligns with the established pattern where inline errors stay minimal and the pipeline provides user-friendly suggestions.
| If you have multiple tenants, run 'azd auth login --tenant-id <tenant-id>' to specify your tenant.`, | |
| Once you have a subscription, run 'azd auth login' again to reload subscriptions., |
| @@ -78,7 +78,8 @@ func (p *DefaultPrompter) PromptSubscription(ctx context.Context, msg string) (s | |||
| return "", errors.New(heredoc.Docf( | |||
| `no subscriptions found. | |||
There was a problem hiding this comment.
[High] Implicit error message contract is undocumented
The YAML rule in error_suggestions.yaml depends on this error containing the substring "no subscriptions found" (case-insensitive) to trigger the enriched suggestion. Consider adding a comment documenting this coupling so future maintainers know not to rephrase the error text without updating the YAML pattern.
| `no subscriptions found. | |
| // NOTE: Error text must contain "no subscriptions found" to match the | |
| // pattern in error_suggestions.yaml. Update both if rewording. | |
| return "", errors.New(heredoc.Docf( |
| # Subscription Errors | ||
| # ============================================================================ | ||
|
|
||
| - patterns: |
There was a problem hiding this comment.
[Medium] Pattern match brittleness
The pattern ""no subscriptions found"" is a strict substring match. If the error text in prompter.go is later rephrased (e.g., singular ""subscription""), this rule would silently stop matching. Consider adding an alternate pattern for robustness:
| - patterns: | |
| - "no subscriptions found" | |
| - "no subscription found" |
| require.NotNil(t, result, "Should match 'no subscriptions found' pattern") | ||
| assert.Equal(t, "No Azure subscriptions were found for your account.", result.Message) | ||
| assert.Contains(t, result.Suggestion, "azd auth login --tenant-id") | ||
| } |
There was a problem hiding this comment.
[Medium] Test doesn't verify links field
The YAML rule includes a links array with a documentation URL, but this test only asserts Message and Suggestion. It might be worth adding a check for links to ensure the documentation reference isn't accidentally removed:
| } | |
| assert.Contains(t, result.Suggestion, "azd auth login --tenant-id") | |
| assert.NotEmpty(t, result.Links, "Should include documentation links") |
| } | ||
| } | ||
|
|
||
| // --- Subscription error rule test --- |
There was a problem hiding this comment.
[Low] Comment style
Minor nit: the decorative separator // --- ... --- isn't used elsewhere in this file. Consider removing it — the function name TestPipeline_NoSubscriptionsFound is already self-documenting.
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Fixes #6419
Description
When users run
azdcommands and no Azure subscriptions are found, the error message now includes actionable guidance for multi-tenant and MFA scenarios.Changes
azd auth login --tenant-id <tenant-id>for multi-tenant scenarios.azd auth logindocumentation.TestPipeline_NoSubscriptionsFoundto verify the YAML rule matches correctly.