Skip to content
This repository was archived by the owner on Jan 13, 2023. It is now read-only.
This repository was archived by the owner on Jan 13, 2023. It is now read-only.

Can exceptions be improved to provide more useful feedback? #114

@scottbelden

Description

@scottbelden

At the moment, when one calls an API incorrectly and an exception is raised, it usually ends with something like this:

ValueError: Request failed validation ({'transaction': ['wrong_type']}) (`exc.context["filter_errors"]` contains more information).

Okay, so I used the wrong type. However, to get the useful information, I have to modify my code from this:

call_api(wrong_type)

to this:

try:
    call_api(wrong_type)
except ValueError as e:
    print(e.context)
    raise

And now I get the useful information such as the following:

{'code': 'wrong_type', 'message': 'Transaction is not valid (allowed types: TryteString, bytearray, bytes, str).', 'context': {'value': <iota.transaction.base.Transaction object at 0x7f500de2c898>, ...}

So now I can fix the wrong_type and remove the exception wrapping. However, it seems like information should be in the original exception message.

Maybe once I use mypy it will catch these type errors, but at least for me it seems that these exceptions could be more helpful from the start.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions