Skip to content

Discussion: what exception to raise for a failed lookup by id? #113

@elliot-100

Description

@elliot-100

Currently get_event(id) and get_group(id) raise built-in IndexError if id is not matched. NB IndexError subclasses base class LookupError.

Although I originally implemented this, I don't think it's correct, as (paraphasing docs) this is intended where an integer subscript is out of range; and id is str not int.

@ptmminh suggested ValueError (docs) but this should be:

raised when an operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.

I think we should be more precise, and so it should be one of:

  • built-in KeyError (docs) which subclasses base class LookupError - as id is a key to a mapping (dict), even though it happens to be inside a list
  • custom exception e.g. IDMatchError which subclasses base class LookupError

Let me know what you think.

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is neededquestionFurther information is requested

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions