Source code for watertap.edb.error

"""
Error classes and utilities for the electrolyte database (EDB).
"""
__author__ = "Dan Gunter"

from typing import Dict
from pprint import pformat


[docs]class Error(Exception): """Abstract base class for all EDB errors.""" pass
[docs]class ConfigGeneratorError(Error): """Base class of errors for ConfigGenerator actions and effects.""" pass
[docs]class DataWrapperError(Error): """ "Base class of errors for DataWrapper actions and effects.""" pass
[docs]class BadConfiguration(DataWrapperError): """Bad configuration provided to build a DataWrapper class."""
[docs] def __init__(self, whoami: str, config: Dict, missing: str = None, why: str = None): if missing: why = f"Missing field '{missing}'" elif why is None: why = "Unknown error" dumped = pformat(config) msg = f"Bad configuration provided to '{whoami}': {why}.\n{dumped}" super().__init__(msg)
[docs]class ValidationError(Error): """Validation error."""
[docs] def __init__(self, err): msg = f"{err}" super().__init__(msg)