Skip to content

Errors

Exceptions raised by libphash.

Every failure of the C library becomes a subclass of :class:PhashError, chosen by its ph_error_t code. The classes also derive from the built-in exception a Python programmer would reach for: an unreadable file is an :class:OSError (with errno, so except FileNotFoundError works), a bad argument a :class:ValueError, a failed allocation a :class:MemoryError.

PhashError

PhashError(message: str, *, code: int = 0, detail: str = '')

Bases: Exception

Base class of every libphash error.

Attributes: code: the ph_error_t value, or 0 for an error raised by the binding itself. code_name: the C name of the code ("PH_ERR_IO"), or "". detail: the C library's description of this failure (for loading: the path and the reason), or "".

ImageIOError

ImageIOError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError, OSError

The path could not be used as an image source (PH_ERR_IO).

errno and filename are filled in when the cause can be told (a missing file, a directory, no permission), so the matching :class:OSError subclass catches it: except FileNotFoundError sees a missing image file.

DecodeError

DecodeError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError

The data could not be decoded into an image. Parent of the four reasons below.

UnsupportedFormatError

UnsupportedFormatError(message: str, *, code: int = 0, detail: str = '')

Bases: DecodeError

The data is in no image format libphash recognizes.

CorruptDataError

CorruptDataError(message: str, *, code: int = 0, detail: str = '')

Bases: DecodeError

The format was recognized, but the data is malformed or truncated.

DecoderUnavailableError

DecoderUnavailableError(message: str, *, code: int = 0, detail: str = '')

Bases: DecodeError

The format was recognized, but this build has no decoder for it.

ImageTooLargeError

ImageTooLargeError(message: str, *, code: int = 0, detail: str = '')

Bases: DecodeError

The image is larger than Config.max_pixels or the library's fixed limits.

InvalidArgumentError

InvalidArgumentError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError, ValueError

An argument is outside the range the C library accepts.

AllocationError

AllocationError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError, MemoryError

A memory allocation failed in the C library.

EmptyImageError

EmptyImageError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError

A hash was requested from a context that holds no image.

RequiresColorError

RequiresColorError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError

A color algorithm was asked for an image loaded in grayscale.

NoStructureError

NoStructureError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError

A Radial digest has no structure to correlate (a flat image).

BatchCancelledError

BatchCancelledError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError

A batch was stopped before every item was started.

DigestKindError

DigestKindError(message: str, *, code: int = 0, detail: str = '')

Bases: PhashError, TypeError

Two digests were compared by a metric their kind does not support.