Skip to content

JSON deserialization does not handle OverflowError #480

Description

Trying to deserialize certain misformatted strings result in an uncaught OverflowError exception instead of passing through the string unchanged. In particular, trying to deserialize a timedelta string such as "50001140846:00021" results in the following:

Traceback (most recent call last):
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 66, in parse_timedelta_string
    return parse_timedelta_from_iso_format(text)
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 34, in parse_timedelta_from_iso_format
    raise ValueError(f"Invalid ISO8601 duration string: {text}")
ValueError: Invalid ISO8601 duration string: 50001140846:00021

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
[...]
  File "lib\site-packages\kiota_serialization_json\json_parse_node.py", line 335, in try_get_anything
    return parse_timedelta_string(value)
  File "lib\site-packages\kiota_abstractions\date_utils.py", line 76, in parse_timedelta_string
    return timedelta(hours=hours, minutes=minutes, seconds=seconds)
OverflowError: days=2083380868; must have magnitude <= 999999999

The issue is that JsonParseNode.try_get_anything() only handles ValueError exceptions instead of also handling OverflowError. Changing this line to catch both ValueError and OverflowError allows deserialization to be successful:

Most likely the other catch handlers in try_get_anything() should be updated as well.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions