Fix panic on azd auth token unsupported output#7356
Fix panic on azd auth token unsupported output#7356weikanglim wants to merge 1 commit intoAzure:mainfrom
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a panic path when azd auth token encounters an unsupported --output format by ensuring errors are surfaced normally (via Cobra) when the command-scoped console/output formatter cannot be resolved, and by preventing the auto-install path from attempting IoC resolution for unrelated command errors.
Changes:
- Improves
--outputunsupported-format error message to be more flag-specific. - Updates Cobra execution flow to only silence errors when a console can be resolved (otherwise let Cobra print the raw error).
- Short-circuits auto-install logic unless the error is specifically
UnsupportedServiceHostError, and adds an integration test to prevent regressions.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/azd/pkg/output/parameter.go | Makes unsupported output errors more explicit about --output. |
| cli/azd/cmd/cobra_builder.go | Avoids suppressing errors when console resolution fails, allowing Cobra to print. |
| cli/azd/cmd/auto_install.go | Prevents panic by only entering service-host auto-install flow for UnsupportedServiceHostError. |
| cli/azd/cmd/auto_install_integration_test.go | Adds regression coverage to ensure unsupported output errors don’t cause a panic and are printed. |
|
|
||
| var execErr error | ||
| require.NotPanics(t, func() { | ||
| execErr = ExecuteWithAutoInstall(context.Background(), rootContainer) |
There was a problem hiding this comment.
Repository guidance prefers using t.Context() in tests so cancellations/deadlines propagate correctly and tests don’t accidentally hang. Consider passing t.Context() into ExecuteWithAutoInstall instead of context.Background().
| execErr = ExecuteWithAutoInstall(context.Background(), rootContainer) | |
| execErr = ExecuteWithAutoInstall(t.Context(), rootContainer) |
| "--scope", | ||
| "https://graph.microsoft.com/.default", | ||
| "--tenant-id", | ||
| "00000000-0000-0000-0000-000000000000", |
There was a problem hiding this comment.
This test currently relies on the auth token command’s default --output value being none to trigger the unsupported-format path. That makes the test brittle if the command’s default output format is corrected in the future (the test could start exercising auth/token acquisition instead). Consider explicitly passing --output none (or another unsupported value) in os.Args so the test always targets the panic regression case deterministically.
| "00000000-0000-0000-0000-000000000000", | |
| "00000000-0000-0000-0000-000000000000", | |
| "--output", | |
| "none", |
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
| stderrBytes, err := io.ReadAll(stderrReader) | ||
| require.NoError(t, err) | ||
|
|
||
| require.ErrorContains(t, execErr, "unsupported format 'none'") |
There was a problem hiding this comment.
What if we just make azd auth token output to be default to json instead of none, so you could use the -o json or no flag and still get the same response?
Part of me feels we should just take that approach and make it easier for users. If we need some other formating in the future, we can always use a different arg, but we would have a default for no arg
vhvb1989
left a comment
There was a problem hiding this comment.
adding a question for re-shaping the fix here
jongio
left a comment
There was a problem hiding this comment.
Reviewed 4 changed files (+65/-8). Dual-model analysis with iterative deepening found no novel issues after deduplicating against existing review feedback.
The fix correctly short-circuits the auto-install path before IoC resolution, preventing the panic. The conditional error silencing in cobra_builder.go is a solid approach - using console resolvability as the proxy for whether middleware handled the error display. Clean fix.
2 existing review threads were already covering the remaining suggestions (t.Context(), explicit --output flag).
LGTM.
Fix panic on
azd auth tokenunsupported output flag.Changes:
auto_install.goto short-circuit if the error isn'tUnsupportedServiceHostError.cobra_builder.goto correctly print error messages if console isn't resolvable (which happens in the case of the output formatter not instantiated from--outputflag).Closes #7303