Skip to content

Skip empty console messages in JSON output mode#7701

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/remove-leading-newlines-auth-token-failure
Draft

Skip empty console messages in JSON output mode#7701
Copilot wants to merge 2 commits intomainfrom
copilot/remove-leading-newlines-auth-token-failure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

azd auth token -ojson emits a spurious {"type":"consoleMessage","data":{"message":"\n"}} line before the error JSON when authentication fails. This is caused by console.Message(ctx, "") calls used as visual separators (blank lines) in text mode — in JSON mode, EventForMessage("") appends a trailing \n to the empty string, producing a meaningless event.

Changes

  • cli/azd/pkg/input/console.go — Early-return in Message() when the message is empty and format is JSON. Empty messages are visual separators with no semantic value in structured output.
  • cli/azd/pkg/input/console_test.go — Added TestAskerConsole_Message_EmptySkippedInJson covering both the skip and the pass-through for non-empty messages.

Before:

$ azd auth token -ojson --tenant-id test
{"type":"consoleMessage","timestamp":"...","data":{"message":"\n"}}
{"error":"fetching token: ...","message":"Authentication with Azure failed.","suggestion":"..."}

After:

$ azd auth token -ojson --tenant-id test
{"error":"fetching token: ...","message":"Authentication with Azure failed.","suggestion":"..."}

Copilot AI changed the title [WIP] Fix leading newlines in azd auth token json output on failure Skip empty console messages in JSON output mode Apr 14, 2026
Copilot AI requested a review from JeffreyCA April 14, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove leading newlines when azd auth token --output json fails

2 participants