Skip to content

Exceptions question #83

Description

@rob-ross

In exceptions.py JSONPointerIndexError, JSONPointerKeyError, and JSONPointerTypeError use multiple inheritance to extend from both JSONPointerResolutionError, and IndexError, KeyError, and TypeError respectively.

Java doesn't have multiple class inheritance. I could get tricky with using interfaces to try to duplicate this, but first I wanted to ask what is your design goal with this class hierarchy? In test_json_pointer.py, you're catching the Python built-ins and not your custom Error classes. Is there a reason you are not just catching JSONPointerIndexError, JSONPointerKeyError, and JSONPointerTypeError?

Thanks!

  • Rob

Activity

  1. jg-rp commented on Aug 2, 2025

    @jg-rp
    Owner

    Hi Rob,

    Inheriting from IndexError, KeyError and TypeError was an afterthought and not part of the original design. I wanted to cater for Python users that might expect handling standard exceptions to work as if they're accessing a dictionary or list. A bit like being able to catch IndexOutOfBoundsException or a custom exception with an independent class hierarchy in Java.

    Testing the standard exceptions in test_json_pointer.py and not those inheriting from JSONPointerResolutionError is an oversight on my part.

    I think you could safely ignore multiple inheritance here and go with something like this:

    Image

    The important part being that JSONPointerResolutionError and its subclasses only occur when resolving a JSON Pointer, not when parsing a JSON Pointer from a string (I can see one place where I'm failing to do this).

    Depending on how strict you're being with your port, you could instead choose to follow Jackson's example and use a "missing" object to indicate the absence of a node instead of throwing exceptions, a bit like JsonNode.path() does, if that would make more sense to your average Java developer (it's been a long time since I wrote any Java 🤷‍♂️).

    Cheers,
    James

  2. Repository owner locked and limited conversation to collaborators on Aug 3, 2025
  3. converted this issue into a discussion #91 on Aug 3, 2025
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions