"""Errors used by *sequence*."""from__future__importannotationsfromcollections.abcimportIterable
[docs]classSequenceError(Exception):"""All *sequence* errors should inherit from this class."""pass
[docs]classShorelineError(SequenceError):"""Raise this exception if there was an error locating the shoreline."""def__init__(self,msg:str):self._msg=str(msg)
[docs]def__str__(self)->str:"""Return an error message in human-readable form."""returnself._msg
[docs]classShelfEdgeError(SequenceError):"""Raise this exception is there was an errors locating the shelf edge."""def__init__(self,msg:str):self._msg=str(msg)
[docs]def__str__(self)->str:"""Return an error message in human-readable form."""returnself._msg
[docs]classOutputValidationError(SequenceError):"""Raise this exception if there is something wrong with an output file."""pass
[docs]classInvalidRowError(OutputValidationError):"""Raise this exception if a required variable is missing from an output file."""def__init__(self,row:int,n_rows:int):self._row=rowself._n_rows=n_rows
[docs]def__str__(self)->str:"""Return error message that includes the requested row."""returnf"row {self._row!r} is out of bounds for output file with {self._n_rows} rows"
[docs]classMissingRequiredVariable(OutputValidationError):"""Raise this exception if a required variable is missing from an output file."""def__init__(self,name:str):self._name=name
[docs]def__str__(self)->str:"""Return error message that includes the name of the missing variable."""returnf"requireed variable ({self._name!r}) is missing from output file"
[docs]classParameterMismatchError(SequenceError):"""Raise this exception if values from two configurations are mismatched."""def__init__(self,keys:Iterable[str]):self.keys=tuple(keys)
[docs]def__str__(self)->str:"""Return an error message with the offending keys."""params=", ".join([repr(key)forkeyinself.keys])returnf"mismatch in parameter{'s'iflen(self.keys)>1else''}: {params}"