Skip to content

xtr_cache_contracts.exception

The errors the caching contract names.

:class:CacheError is the root every caching error derives from, including every one an implementation adds, so catching it catches anything caching can go wrong with, whichever package raised it. :class:InvalidArgumentError is the one the interfaces here document raising.

CacheError

Bases: Exception

Base class for every error raised through the caching contract.

Catch this to handle anything caching can go wrong with, whichever package raised it; catch a subclass to handle one cause. Every subclass carries the data a caller needs as typed attributes and composes its own message from them.

A backend failing is not one of those causes: a cache is an optimisation, so a pool reports a backend it cannot reach by returning False rather than by raising. What does raise is a mistake in the calling code — a key no pool accepts, a tag on an item that cannot carry one.

InvalidArgumentError

InvalidArgumentError(reason: str)

Bases: CacheError, ValueError

A cache was given a key, a tag or an option it cannot work with.

An empty key, one holding a reserved character, a negative beta. Raised where the argument is given, before anything reaches a backend.

Also a :class:ValueError, so code that already guards its input with except ValueError keeps working without learning a new exception.

Attributes:

  • reason (str) –

    What is wrong with the argument.

Record what is wrong with the argument.