Exceptions¶
exceptions
¶
Custom exceptions provided by the flepimop2 package.
Flepimop2Error
¶
Bases: Exception
Base class for exceptions provided by flepimop2.
This class serves as the root for all custom exceptions in the flepimop2 library.
Flepimop2ValidationError(issues)
¶
Bases: Flepimop2Error
Exception raised for validation errors from flepimop2.
This exception's main purpose is to signal that validation has failed
within the flepimop2 library and provides detailed information about
the validation issues encountered, typically provided by an external
provider package. The main benefit of this exception is to encapsulate
multiple validation issues into a single error object, making it easier
to handle and report validation failures as well as providing a consistent
interface for validation errors across different parts of the flepimop2
library.
Attributes:
| Name | Type | Description |
|---|---|---|
issues |
A list of |
Examples:
>>> from pprint import pprint
>>> from flepimop2.exceptions import (
... Flepimop2ValidationError,
... ValidationIssue,
... )
>>> issues = [
... ValidationIssue(
... msg="Model requires undefined parameter 'gamma'.",
... kind="missing_parameter",
... ctx={"parameter": "gamma", "transition": "gamma * (S / N)"},
... ),
... ValidationIssue(
... msg="Compartment 'E' is unreachable.",
... kind="unreachable_compartment",
... ctx={"compartment": "E"},
... ),
... ]
>>> exception = Flepimop2ValidationError(issues)
>>> pprint(exception.issues)
[ValidationIssue(msg="Model requires undefined parameter 'gamma'.",
kind='missing_parameter',
ctx={'parameter': 'gamma', 'transition': 'gamma * (S / N)'}),
ValidationIssue(msg="Compartment 'E' is unreachable.",
kind='unreachable_compartment',
ctx={'compartment': 'E'})]
>>> print(exception)
2 validation issues encountered:
- [missing_parameter] Model requires undefined parameter 'gamma'. (parameter=gamma, transition=gamma * (S / N))
- [unreachable_compartment] Compartment 'E' is unreachable. (compartment=E)
>>> raise Flepimop2ValidationError(issues)
Traceback (most recent call last):
...
flepimop2.exceptions._flepimop2_validation_error.Flepimop2ValidationError: 2 validation issues encountered:
- [missing_parameter] Model requires undefined parameter 'gamma'. (parameter=gamma, transition=gamma * (S / N))
- [unreachable_compartment] Compartment 'E' is unreachable. (compartment=E)
Initialize the Flepimop2ValidationError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issues
|
list[ValidationIssue]
|
A list of |
required |
Source code in src/flepimop2/exceptions/_flepimop2_validation_error.py
93 94 95 96 97 98 99 100 101 102 103 | |
ValidationIssue(msg, kind, ctx=None)
dataclass
¶
Represents a single validation issue encountered during data validation.
Attributes:
| Name | Type | Description |
|---|---|---|
msg |
str
|
A human readable description of the validation issue. |
kind |
str
|
The type/category of the validation issue. |
ctx |
dict[str, Any] | None
|
Optional context providing additional information about the issue. |
Examples:
>>> from pprint import pprint
>>> from flepimop2.exceptions import ValidationIssue
>>> issue = ValidationIssue(
... msg="Invalid wrapper data format.",
... kind="invalid_format",
... ctx={"expected_format": "JSON", "line": 42},
... )
>>> pprint(issue)
ValidationIssue(msg='Invalid wrapper data format.',
kind='invalid_format',
ctx={'expected_format': 'JSON', 'line': 42})