aws / aws/git-remote-codecommit

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

Offen
#42 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
289
Forks
40
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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
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/python@3.9/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/python@3.9/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/python@3.9/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:

```json
{
"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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Der Traceback verweist auf git_remote_codecommit/__init__.py, einschließlich main() und Context.from_url(); beginne dort und verfolge session.get_credentials() bis zum Fehler von credential_process. Reproduziere das Problem mit einem CLI-Anbieter für Anmeldeinformationen, der Nicht-JSON ausgibt, und überprüfe, dass der Befehl die Antwort des Anbieters oder einen anderen aussagekräftigen Fehler bei den Anmeldeinformationen meldet, statt JSONDecodeError.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
aws, git, python
Bereich
authentication, cli, cloud
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.