Err1
Err1¶
- class Err1[source]¶
Bases:
configpile.userr.Err
Describes a single error
This error stores a sequence of contexts, which are key/value pairs describing in which context the error occurred. Contexts are used for explaining to the user where the error occurred. They shouldn’t be used, in principle, to wrap additional information about the error.
Attributes
Note: attributes inherited from parent classes are not shown here, if any
Error message
Contexts in which the error appears, from old to new
Methods
Returns an error if the given predicate is false, otherwise returns None.
Collect a possibly empty sequence of (optional) errors into an optional single error
Collect a non-empty sequence of errors into a single error
Returns a sequence of all contained errors
Adds to this error information about the context in which it occurred
Creates a single error
Returns a Markdown-formatted summary of this error (or list of errors)
Pretty prints an error on the console
List of members of Err1
- errors()[source]¶
Returns a sequence of all contained errors
If this is not a collection of errors
ManyErr
, returns a sequence with a single item, this instance itself.
- markdown(include_contexts=True)[source]¶
Returns a Markdown-formatted summary of this error (or list of errors)
- in_context(**contexts)[source]¶
Adds to this error information about the context in which it occurred
- __init__(msg, contexts)¶
- static check(predicate, msg, **contexts)¶
Returns an error if the given predicate is false, otherwise returns None.
Example
>>> a = -1 >>> b = 2 >>> Err.collect(Err.check(a >= 0, "a < 0"), Err.check(b >= 0, "b < 0")) Err1(msg='a < 0', contexts=[])
- static collect(*errs)¶
Collect a possibly empty sequence of (optional) errors into an optional single error
- static collect1(first_error, *additional_errors)¶
Collect a non-empty sequence of errors into a single error
Example
We can also collect errors coming from a list using the following syntax
>>> errors = [Err.make('err 1'), Err.make('err 2'), Err.make('err 3')] >>> Err.collect1(*errors) ManyErr(errs=...)
- Parameters
- Raises
ValueError – If no error is provided
- Return type
- Returns
A consolidated error
- static make(msg, **contexts)¶
Creates a single error
Example
>>> Err.make("test error") Err1(msg='test error', contexts=[])