aws / aws/git-remote-codecommit

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

Aperta
#42 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
289
Fork
40
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Il traceback punta a git_remote_codecommit/__init__.py, inclusi main() e Context.from_url(); inizia da lì e segui session.get_credentials() fino all’errore di credential_process. Riproduci il problema con un provider di credenziali CLI che emetta dati non JSON e verifica che il comando riporti la risposta del provider o un altro errore significativo relativo alle credenziali invece di JSONDecodeError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
aws, git, python
Ambito
authentication, cli, cloud
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.