Source code for calliope.exceptions

Copyright (C) 2013-2018 Calliope contributors listed in AUTHORS.
Licensed under the Apache 2.0 License (see LICENSE file).

Exceptions and Warnings.


import textwrap
import warnings

# Enable simple format when printing ModelWarnings
formatwarning_orig = warnings.formatwarning

def _formatwarning(message, category, filename, lineno, line=None):
    """Formats ModelWarnings as "Warning: message" without extra crud"""
    if category == ModelWarning:
        return 'Warning: ' + str(message) + '\n'
        return formatwarning_orig(message, category, filename, lineno, line)

warnings.formatwarning = _formatwarning

[docs]class ModelError(Exception): """ ModelErrors should stop execution of the model, e.g. due to a problem with the model formulation or input data. """ pass
[docs]class BackendError(Exception): pass
[docs]class ModelWarning(Warning): """ ModelWarnings should be raised for possible model errors, but where execution can still continue. """ pass
[docs]class BackendWarning(Warning): pass
def warn(message, _class=ModelWarning): warnings.warn(message, _class)