danielgtaylor / danielgtaylor/python-betterproto
Better exception messages
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I think anyone who has used the library for a while will eventually run into an issue that is made hard to debug by the error messages when serialising and deserialising fails. Consider an error like:
File "betterproto/__init__.py", line 767, in __bytes__
output += _serialize_single(
File "betterproto/__init__.py", line 359, in _serialize_single
value = _preprocess_single(proto_type, wraps, value)
File "betterproto/__init__.py", line 325, in _preprocess_single
return struct.pack(_pack_fmt(proto_type), value)
struct.error: argument out of range
The message is relatively unclear as to what has gone wrong especially as it does not include the field which was out of the range and the value that caused the error.
Ideally the error would tell you the name of the field that errored, the value and the value the range has to be in.
File "betterproto/__init__.py", line 767, in __bytes__
output += _serialize_single(
File "betterproto/__init__.py", line 359, in _serialize_single
value = _preprocess_single(proto_type, wraps, value)
File "betterproto/__init__.py", line 325, in _preprocess_single
return struct.pack(_pack_fmt(proto_type), value)
struct.error: argument out of range
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
...
File "betterproto/__init__.py", line 775, in __bytes__
raise SerialisationError(field, value) from e
SerialisationError: Failed to serialize field 'rtime32_start_time', with value 123456789123456789, value should be in [0, 2**32)
This obviously could be adapted for more errors than just the struct error, but it would be a good easy starting point and would incure no runtime cost in newer python versions.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne in betterproto/init.py bei bytes, _serialize_single und _preprocess_single und folge dem im Bericht gezeigten struct.pack-Fehler. Prüfe, wie SerialisationError ausgelöst wird, und stelle sicher, dass das fertige Verhalten bei Serialisierungsfehlern aufgrund von Werten außerhalb des gültigen Bereichs das Feld, seinen Wert und den gültigen Bereich angibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Feature
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100