marsh.errors

Collection of common errors used throughout the framework.

exception MarshError(*args, path='')[source]

Base class for marsh errors.

Allows tracking of the path that produced the error.

Parameters:
  • *args – General exception arguments.

  • path (str) – The path that produced the error.

Return type:

None

append(field)[source]

Append a field to the path of this error.

Return type:

None

Parameters:

field (str) –

prepend(field)[source]

Prepend a field to the path of this error.

Return type:

None

Parameters:

field (str) –

exception PathError(*args, path='')[source]

Accessing non-existing fields or indices.

Also used for path formatting errors.

Parameters:

path (str) –

Return type:

None

exception UnmarshalError(msg='', path='', element='???', type='???')[source]

Failure to unmarshal an element to a specific type.

Parameters:
  • msg (str) –

  • path (str) –

  • element (marsh.element.ElementType) –

  • type (Any) –

Return type:

None

exception MissingValueError(msg='', path='', element='???', type='???')[source]

Required value is missing.

Parameters:
  • msg (str) –

  • path (str) –

  • element (marsh.element.ElementType) –

  • type (Any) –

Return type:

None

exception MarshalError(*args, path='')[source]

Failure to serialize a value.

Parameters:

path (str) –

Return type:

None

exception ConfigFileError(*args, path='')[source]

Base error for config files.

Parameters:

path (str) –

Return type:

None

maybe_handle_error(callback: Callable[[MarshError], Any]) contextlib.AbstractContextManager[source]
maybe_handle_error(callback: Callable[[_E], Any], error: Type[_E]) contextlib.AbstractContextManager

Context manager that invokes a callback when catching an error.

The error is propagated and the callback ignored if the environmental variable MARSH_FULL_ERROR is set and not empty.

The error is passed to the callback.

Parameters:

callback (Callable[[Any], Any]) – Callback function which may be called with the caught error.

Return type:

Iterator[None]

Returns:

Context manager.

prepend(field)[source]

Catches any marsh error, prepends a field to it and then re-raises the error.

Parameters:

field (Any) – The field to prepend to the marsh error path attribute.

Return type:

Iterator[None]

Returns:

Context manager.