calliope.exceptions
¶
Exceptions and Warning handling.
formatwarning_orig = warnings.formatwarning
module-attribute
¶
ModelError
¶
Bases: Exception
ModelErrors should stop execution of the model, e.g. due to a problem with the model formulation or input data.
ModelWarning
¶
Bases: Warning
ModelWarnings should be raised for possible model errors, but where execution can still continue.
print_warnings_and_raise_errors(warnings=None, errors=None, during='model processing', bullet=' * ')
¶
Concatenate collections of warnings/errors and print (warnings) / raise ModelError (errors) with a bullet point list of the concatenated collections.
Lists will return simple bullet lists: E.g. warnings=["foo", "bar"] becomes:
Possible issues found during model processing:
* foo
* bar
Dicts of lists will return nested bullet lists: E.g. errors={"foo": ["foobar", "foobaz"]} becomes:
Errors during model processing:
* foo
* foobar
* foobaz
Parameters:
Name | Type | Description | Default |
---|---|---|---|
warnings |
Optional[Union[list[str], dict[str, list[str]]]]
|
List of warning strings or dictionary of warning strings. If None or an empty list, no warnings will be printed. Defaults to None. |
None
|
errors |
Optional[Union[list[str], dict[str, list[str]]]]
|
List of error strings or dictionary of error strings. If None or an empty list, no errors will be raised. Defaults to None. |
None
|
during |
str
|
Substring that will be placed at the top of the concatenated list of warnings/errors to point to during which phase of data processing they occurred. Defaults to "model processing". |
'model processing'
|
bullet |
str
|
Type of bullet points to use. Defaults to " * ". |
' * '
|
Raises:
Type | Description |
---|---|
ModelError
|
If errors is not None or is a non-empty list/dict |