module documentation

Exception definitions and pretty-printing.

Exception NTTError An error class we can control and pretty-print.
Function docstring_for_NTTError_from Add a docstring to an NT2Error_from function.
Function friendly_exceptions Catch and pretty-print any exceptions when calling.
Function inspect_exception Pretty-print an exception to stderr for the user to see.
Function mk_require_support Return a decorator that raises an exception if format_name support is not installed.
Function NTTError_from Return an NTTError based on the exception if possible.
Function NTTError_from_NTTError Return exc, as-is.
def docstring_for_NTTError_from(func: Callable) -> Callable: (source)

Add a docstring to an NT2Error_from function.

Parameters
func:CallableAn NT2Error_from function.
Returns
CallableThe same function, with a new docstring.
@wrapt.decorator
def friendly_exceptions(wrapped, instance, args, kwargs): (source)

Catch and pretty-print any exceptions when calling.

# noqa: DAR101 wrapped args instance kwargs # noqa: DAR201

def inspect_exception(exc: Exception): (source)

Pretty-print an exception to stderr for the user to see.

Parameters
exc:ExceptionAny Exception. After printing, it is swallowed, not raised.
def mk_require_support(*, format_name: str, supported: bool, extras_name: str) -> Callable: (source)

Return a decorator that raises an exception if format_name support is not installed.

Parameters
format_name:strThe name of the format.
supported:boolWhether the format is supported.
extras_name:strThe name of the corresponding extras in the Python package.
Returns
CallableA decorator that raises an exception if format_name support is not installed.
@singledispatch
def NTTError_from(exc: Exception) -> NTTError: (source)

Return an NTTError based on the exception if possible.

Otherwise, raise the original exception.

Parameters
exc:ExceptionAny exception.
Returns
NTTErrorUndocumented
Raises
excIf exc can't be converted to an NTTError.
@NTTError_from.register
def NTTError_from_NTTError(exc: NTTError) -> NTTError: (source)

Return exc, as-is.

This allows us to uniformly handle exceptions that are already NTTErrors.

Parameters
exc:NTTErrorAn NTTError.
Returns
NTTErrorThe same NTTError.