Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #42

Open
john-aws opened this issue Mar 22, 2023 · 0 comments

Comments

@john-aws
Copy link

If your underlying credentials profile uses a CLI credential provider and that CLI request fails for some reason, git commands will fail with an unobvious error:

me:src$ git pull
Traceback (most recent call last):
  File "/usr/local/bin/git-remote-codecommit", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/git_remote_codecommit/__init__.py", line 176, in main
    context = Context.from_url(remote_url)
  File "/usr/local/lib/python3.9/site-packages/git_remote_codecommit/__init__.py", line 148, in from_url
    credentials = session.get_credentials()
  File "/Users/me/Library/Python/3.9/lib/python/site-packages/botocore/session.py", line 430, in get_credentials
    self._credentials = self._components.get_component(
  File "/Users/me/Library/Python/3.9/lib/python/site-packages/botocore/credentials.py", line 1962, in load_credentials
    creds = provider.load()
  File "/Users/me/Library/Python/3.9/lib/python/site-packages/botocore/credentials.py", line 948, in load
    creds_dict = self._retrieve_credentials_using(credential_process)
  File "/Users/me/Library/Python/3.9/lib/python/site-packages/botocore/credentials.py", line 974, in _retrieve_credentials_using
    parsed = botocore.compat.json.loads(stdout.decode('utf-8'))
  File "/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/[email protected]/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The issue seems to be that the underlying CLI credential provider is expected to return JSON of the form:

{
  "Version": 1,
  "AccessKeyId": "ASIAxxxxxxx",
  "SecretAccessKey": "xxxxx",
  "SessionToken": "xxxxx",
  "Expiration": "2023-03-23T01:02:03Z"
}

If, instead, it fails and returns something else that is not JSON, then git-remote-codecommit fails to decode the not-JSON and throws an ugly error message that does not give the user a good idea of what has gone wrong.

Wonder if the git-remote-codecommit helper could catch these JSON decode errors and do something more meaningful to the user e.g. simply surface the underlying credentials provider response verbatim. Thanks.

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

No branches or pull requests

1 participant