# 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

```python
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

```python
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

```python
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

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

Bases: `DecodeError`

The data is in no image format libphash recognizes.

## CorruptDataError

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

Bases: `DecodeError`

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

## DecoderUnavailableError

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

Bases: `DecodeError`

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

## ImageTooLargeError

```python
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

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

Bases: `PhashError`, `ValueError`

An argument is outside the range the C library accepts.

## AllocationError

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

Bases: `PhashError`, `MemoryError`

A memory allocation failed in the C library.

## EmptyImageError

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

Bases: `PhashError`

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

## RequiresColorError

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

Bases: `PhashError`

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

## NoStructureError

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

Bases: `PhashError`

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

## BatchCancelledError

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

Bases: `PhashError`

A batch was stopped before every item was started.

## DigestKindError

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

Bases: `PhashError`, `TypeError`

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