parasite.errors

Brief

This submodule contains the custom exceptions used by the parasite package.

Usage

The exceptions are used to signal errors in the code. They are raised when the code encounters an error that it cannot handle. The exceptions are used to provide a detailed error message to the user.

from parasite import errors

try:
    # code that may raise an exception
except errors.ValidationError as e:
    print(e)

Member Reference

exception parasite.errors.ValidationError[source]

Validation error that is raised when a value does not match the expected type.

Inheritance:

Inheritance diagram of parasite.errors.ValidationError

Example usage:

Let’s assume we have the following schema:

from parasite import p

schema = p.obj(
    {
        "name": p.string().required(),
        "age": p.number().integer().min(0).optional(),
    }
)

The schema will parse the following objects:

from parasite import errors

try:
    schema.parse({})

except errors.ValidationError as e:
    print(e)
    # key "name" not found, but is required
add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.