Skip to content

Exception Utils

Utility functions for exceptions.

normalize_errors(method)

Wraps a component method so any error that is not a BaseError becomes an UnexpectedError.

Apply this only to a method of a document-processing component: loader, parser, chunker, downloader, etc.

  1. BaseError passes through unchanged.
  2. BaseDocProcError without component is filled with type(self).__name__ where wrapped.
  3. A BaseError with no reference ID gets one.
  4. Any other error is re-raised as an UnexpectedError naming the component class, chained from the original error.

Parameters:

Name Type Description Default
method Callable[Concatenate[Any, P], R]

The component method to wrap.

required

Returns:

Type Description
Callable[Concatenate[Any, P], R]

Callable[Concatenate[Any, P], R]: The wrapped method.