fix(auth): Azure DevOps az-CLI token returns None on undecodable output instead of crashing#3527
Open
jawwad-ali wants to merge 1 commit into
Open
Conversation
…codable output _acquire_via_az_cli runs 'az account get-access-token' with text=True, so subprocess.run decodes stdout with the locale encoding and raises UnicodeDecodeError (a ValueError sibling, NOT a JSONDecodeError) when the output can't be decoded. That escaped the except (OSError, TimeoutExpired, JSONDecodeError, KeyError) tuple and crashed a helper whose contract is to return str | None. Add UnicodeDecodeError to the tuple. Test patches subprocess.run to raise UnicodeDecodeError and asserts resolve_token returns None (fails before: the error propagated). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
AzureDevOpsAuth._acquire_via_az_clirunsaz account get-access-tokenwithtext=True, then parses the JSON:With
text=True,subprocess.rundecodes stdout using the locale encoding, so ifazemits bytes that aren't decodable there it raisesUnicodeDecodeErrorinsiderun()— beforejson.loadsever runs.UnicodeDecodeErroris aValueErrorsibling but not aJSONDecodeError, so it isn't caught and it crashes a helper whose entire contract is to returnstr | None.Fix
Add
UnicodeDecodeErrorto the except tuple so undecodable output degrades toNonelike every other failure mode. One-token change; direction unambiguous given thestr | Nonereturn contract and the sibling encoding guards elsewhere in the codebase.Test
test_resolve_token_azure_cli_undecodable_output_returns_nonepatchessubprocess.runto raiseUnicodeDecodeErrorand assertsresolve_token(...) is None— fails before (the error propagated), passes after.🤖 Written with the assistance of Claude Code (AI). Bug self-found; fix/tests verified locally (fail-before / pass-after), ruff clean.