creativecommons / creativecommons/quantifying
Swallowing Critical GitHub API Errors (KeyError) in github_fetch.py
- Lingua principale
- Python
- Stelle
- 48
- Fork
- 74
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## Description
In `scripts/1-fetch/github_fetch.py`, the script fetches public repository counts for various Creative Commons tools. When parsing the GitHub API search response, the code expects to find `"total_count"` in the returned JSON object:
`count = search_data["total_count"]`
However, if the GitHub API returns an error response (such as "API Rate Limit Exceeded" or "Invalid Token" / "Bad credentials"), `"total_count"` will not exist in the response payload. As a result, the script encounters a `KeyError` on `"total_count"`, which is caught by:
```python
except KeyError as e:
raise shared.QuantifyingException(f"KeyError: {e}", 1)
```
This swallows the actual error details returned by the GitHub API (e.g., in the `"message"` field), making debugging extremely difficult without manually outputting the API response payload.
## Reproduction
1. Run `python scripts/1-fetch/github_fetch.py` using a rate-limited network or an invalid/expired `GH_TOKEN`.
2. The GitHub API returns a JSON response lacking the `"total_count"` key (e.g., containing `"message": "API rate limit exceeded..."` or `"message": "Bad credentials"`).
3. The script throws `KeyError: 'total_count'`, which is converted into `QuantifyingException("KeyError: 'total_count'", 1)`.
4. Observe the script exiting with a generic `KeyError: 'total_count'` exception, concealing the actual API rate limiting or authentication message.
## Expectation
The script should check for GitHub API error messages (like `"message"` or other error indicators in the JSON response) before attempting to access `"total_count"`, logging the specific error payload from GitHub to provide clarity on why the request failed.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia in scripts/1-fetch/github_fetch.py, analizzando la risposta della GitHub API e l’accesso a search_data["total_count"]. Riproduci il problema con una richiesta soggetta a rate limit o con un GH_TOKEN non valido, quindi verifica che il fallimento risultante esponga il messaggio di errore o il payload restituito da GitHub, invece del solo KeyError: 'total_count'.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- github, python
- Ambito
- api, data
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Tranquilla
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 78/100