Skip to content

Conversation

@rahuldevikar761
Copy link
Collaborator

@rahuldevikar761 rahuldevikar761 commented Dec 4, 2025

Added a method to clean JSON output from Azure CLI commands to remove control characters and non-JSON content.

The Problem
The error was caused by invalid control characters (specifically 0x0C - form feed character) in the Azure CLI output. When the tool ran az account show --output json, the output contained non-JSON characters that prevented successful JSON deserialization.

Added a method to clean JSON output from Azure CLI commands to remove control characters and non-JSON content.
Copilot AI review requested due to automatic review settings December 4, 2025 02:49
@rahuldevikar761 rahuldevikar761 requested review from a team as code owners December 4, 2025 02:49
Copilot finished reviewing on behalf of rahuldevikar761 December 4, 2025 02:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds JSON output sanitization to Azure CLI command processing to handle cases where Azure CLI returns control characters or non-JSON content in its output. The implementation introduces a new CleanJsonOutput helper method that removes control characters and strips any text before the first JSON bracket.

Key changes:

  • Added CleanJsonOutput method to remove control characters (0x00-0x1F) and locate JSON start markers
  • Integrated cleaning logic into four Azure CLI methods: GetCurrentAccountAsync, ListResourceGroupsAsync, ListAppServicePlansAsync, and ListLocationsAsync
  • Added null/empty output validation after cleaning in all affected methods

Added JSON output cleaning functionality to improve parsing of Azure CLI responses.
…aning

- Added CleanAzureCliJsonOutput method to JsonDeserializationHelper
- Updated AzureCliService, AzureAuthValidator, and BotConfigurator to use the shared helper
- Removed duplicate CleanJsonOutput methods from individual services
- Fixes JSON parsing errors when Azure CLI outputs control characters (0x0C) on Windows
Copilot AI review requested due to automatic review settings December 4, 2025 03:21
Copilot finished reviewing on behalf of rahuldevikar761 December 4, 2025 03:23
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

…rom main

- Added tenantId parameter back to GetAccessTokenAsync calls
- Restored comprehensive error handling for delete endpoint failures
- Re-added Microsoft.Agents.A365.DevTools.Cli.Exceptions using statement
- Maintains JSON cleaning functionality while aligning with main branch changes
Copilot AI review requested due to automatic review settings December 4, 2025 03:34
Copilot finished reviewing on behalf of rahuldevikar761 December 4, 2025 03:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

// Remove control characters (0x00-0x1F except \r, \n, \t)
// These characters can appear in Azure CLI output on Windows
var cleaned = new System.Text.StringBuilder(output.Length);
foreach (char c in output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what is different with your tenant?

When would we get control characters?

In preview001 or ztaitest12 or testcsaa where we have been testing so far, we didn't see this. Wondering if this can have a negative impact for those tenants/users.
How do we ensure that?

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.

3 participants