az repos policy create can't read file

Open
#1,353 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
azure, python
Domain
cli, devtools

Research direction

Start in azext_devops/dev/repos/policy.py at create_policy_configuration_file and its json.load call. Reproduce the Windows PowerShell-generated template with az repos policy create --config, then inspect how the file is opened and how the command handles the reported JSONDecodeError. Done means the command can read the described file without this failure.

Written by the indexing model from the issue text.

Description

I create a file manually and named if template.json
I did some token replacement and saved it using this command
Out-File -FilePath $templateFile -InputObject $updatedContents

Whatever output PS outputs is not recognized by az repos policy create --config - probably UTF-8

I changed it to ASCII encoding and it worked fine
Out-File -FilePath $templateFile -InputObject $updatedContents -Encoding ASCII

Command Name
az repos policy create Extension Name: azure-devops. Version: 0.26.0.

Errors:

The command failed with an unexpected error. Here is the traceback:
Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 663, in execute
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 718, in _run_job
  File "C:\Users\kkilton\.azure\cliextensions\azure-devops\azext_devops\dev\common\exception_handler.py", line 31, in azure_devops_exception_handler
    reraise(*sys.exc_info())
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\six.py", line 719, in reraise
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 697, in _run_job
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/__init__.py", line 333, in __call__
  File "D:\a\_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler
  File "C:\Users\kkilton\.azure\cliextensions\azure-devops\azext_devops\dev\repos\policy.py", line 75, in create_policy_configuration_file
    configuration = json.load(f)
  File "json\__init__.py", line 293, in load
  File "json\__init__.py", line 346, in loads
  File "json\decoder.py", line 337, in decode
  File "json\decoder.py", line 355, in raw_decode
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Put any pre-requisite steps here...
  • az repos policy create --config {}

Expected Behavior

Notepad++ can read this file just fine and no comparison issues between the files, AZ CLI should be able to read the file.

Environment Summary

Windows-10-10.0.19045-SP0
Python 3.10.10
Installer: MSI

azure-cli 2.47.0 *

Extensions:
azure-devops 0.26.0

Dependencies:
msal 1.20.0
azure-mgmt-resource 22.0.0

Additional Context

Dominant language
Python
Stars
683
Forks
278
Avg merge
4d 11h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/azure-devops-cli-extension

All issues in Azure/azure-devops-cli-extension

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.