Repository navigation
fix: emit extension errors as JSON on stderr in JSON output mode - #10861
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 26 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Main added extensionAction tests that suppressed update checks via os.Args --output=json. Point them at PreParsedOutput so they match the JSON output mode fix.
7706046 to
30a7fa1
Compare
There was a problem hiding this comment.
🟡 Changes recommended
A moderate active issue remains because JSON output variants are normalized in one path but not in isJsonOutput, so telemetry or update-banner text may still pollute the promised JSON-only stderr stream.
1 open issue
What changed in this PR
This pull request updates extension commands to emit JSON-formatted errors on stderr when JSON output is requested, while keeping stdout empty and preserving exit code behavior.
Changes:
- Pre-parses and normalizes supported
--outputand-oflag forms. - Selects the JSON formatter for flag-parsing-disabled extension commands.
- Updates extension, formatter, and flag-parsing test coverage.
- Retains unresolved workflow-scoped output-state issues and inconsistent normalization in related JSON detection.
This pull request requires changes.
| File | Summary |
|---|---|
cli/azd/internal/global_command_options.go |
Adds normalized pre-parsed output state to global command options. |
cli/azd/cmd/extensions.go |
Uses the pre-parsed output mode for formatter and update-warning behavior. |
cli/azd/cmd/extensions_test.go |
Tests extension error output across JSON and text modes and flag spellings. |
cli/azd/cmd/extension_test.go |
Removes tests for the deleted argument-scanning helper. |
cli/azd/cmd/extension_exit_code_test.go |
Updates test setup to provide pre-parsed JSON output explicitly. |
cli/azd/cmd/extension_action_test.go |
Updates extension action tests to use pre-parsed output state. |
cli/azd/cmd/container.go |
Adds formatter selection supporting JSON output for flag-parsing-disabled commands. |
cli/azd/cmd/container_test.go |
Verifies formatter behavior and core-command output precedence. |
cli/azd/cmd/auto_install.go |
Captures and normalizes output values during global flag pre-parsing. |
cli/azd/cmd/auto_install_test.go |
Covers output flag forms, ordering, normalization, and -- termination. |
Review effort: Lite
Treat uppercase and whitespace variants such as --output JSON as JSON so telemetry notices and the update banner do not leak unstructured text onto stderr.
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|

Summary
Extension commands run with
-o jsonprinted errors as plainERROR:text on stdout. They now match core commands: the error goes to stderr as one JSONconsoleMessageline, stdout stays empty, and the exit code is still 1.Changes
parseGlobalFlagskeeps the early-parsed--outputvalue inGlobalCommandOptions.PreParsedOutputgetCommandFormatter: for commands withDisableFlagParsing(extension commands), it picks the JSON formatter from the pre-parsed value before the console is created. Core commands keep usingoutput.GetCommandFormatterisJsonOutputFromArgs. The update-warning check uses the pre-parsed value, so it handles--output json,-o json,--output=json,-o=json, and-ojson. The last flag wins, and parsing stops at--os.Argsnow setPreParsedOutputTesting
go test ./cmd/,./internal/, and./pkg/output/pass--, JSON stderr error shape, text mode unchanged, and core commands ignoring pre-parsed output-o json/--output json/-ojsonconsoleMessageERROR:on stdout, stderr emptyconsoleMessageon stderr, stdout emptyFixes #10497