apimodel.errors#

Pretty errors.

Module Contents#

exception apimodel.errors.LocError(error: Exception, loc: RawLoc = '__root__')[source]#

Error with a location.

error :Exception[source]#

Original error.

loc :Loc[source]#

Location where the error ocurred.

exception apimodel.errors.ValidationError(*errors: ErrorList, model: Type[apimodel.apimodel.APIModel])[source]#

Pretty validation error inspired by pydantic.

errors :Sequence[LocError][source]#

Collected errors.

model :Type[apimodel.apimodel.APIModel][source]#

The model in which the error ocurred. Used for debugging.

property locations(self) Sequence[Tuple[Loc, Exception]][source]#

Get flattened locations and errors.

apimodel.errors.catch_errors(model: apimodel.tutils.MaybeType[apimodel.apimodel.APIModel]) Iterator[ErrorCatcher][source]#

Catch errors and raise a ValidationError if at least one is present.

Examples

>>> with apimodel.errors.catch_errors(model) as catcher:
>>>     for name, function in function:
>>>         with catcher.catch(loc=function.__name__):
>>>             function()