From 7552c7d92b8c004173ebd5550bbe68c759eec162 Mon Sep 17 00:00:00 2001 From: Josh Horton Date: Thu, 12 Dec 2024 14:51:27 +0000 Subject: [PATCH] add base error, change MissingProtocolUnitError -> MissingUnitResultError --- gufe/protocols/__init__.py | 2 +- gufe/protocols/errors.py | 18 ++++++++++-------- gufe/protocols/protocoldag.py | 12 ++++++------ gufe/tests/test_protocol.py | 8 ++++---- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gufe/protocols/__init__.py b/gufe/protocols/__init__.py index 6f7a20dd..155ddacc 100644 --- a/gufe/protocols/__init__.py +++ b/gufe/protocols/__init__.py @@ -1,7 +1,7 @@ """Defining processes for performing estimates of free energy differences""" from .errors import ( - MissingProtocolUnitError, + MissingUnitResultError, ProtocolAnalysisError, ProtocolExecutionError, ProtocolSetupError, diff --git a/gufe/protocols/errors.py b/gufe/protocols/errors.py index 9c143ef8..ec676af9 100644 --- a/gufe/protocols/errors.py +++ b/gufe/protocols/errors.py @@ -1,28 +1,30 @@ # This code is part of OpenFE and is licensed under the MIT license. # For details, see https://github.com/OpenFreeEnergy/gufe +class BaseGufeError(Exception): + """The base gufe error that other errors should subclass.""" # Protocol Errors -class ProtocolValidationError(Exception): +class ProtocolValidationError(BaseGufeError): """Error when the protocol setup or settings can not be validated.""" -class ProtocolSetupError(Exception): +class ProtocolSetupError(BaseGufeError): """Error when executing the setup unit of the protocol.""" -class ProtocolExecutionError(Exception): +class ProtocolExecutionError(BaseGufeError): """Error when executing the production unit of the protocol.""" -class ProtocolAnalysisError(Exception): +class ProtocolAnalysisError(BaseGufeError): """Error when trying to perform some analyses after the protocol has been executed.""" # Protocol Results Errors -class MissingProtocolUnitError(Exception): - """Error when a ProtocolDAGResult is missing a protocol unit.""" +class MissingUnitResultError(BaseGufeError): + """Error when a ProtocolDAGResult is missing a unit result.""" -class ProtocolUnitFailureError(Exception): - """Error when a ProtocolDAGResult contains an failed protocol unit.""" +class ProtocolUnitFailureError(BaseGufeError): + """Error when a ProtocolDAGResult contains a failed protocol unit.""" diff --git a/gufe/protocols/protocoldag.py b/gufe/protocols/protocoldag.py index 43564f0d..03794ff9 100644 --- a/gufe/protocols/protocoldag.py +++ b/gufe/protocols/protocoldag.py @@ -14,7 +14,7 @@ import networkx as nx from ..tokenization import GufeKey, GufeTokenizable -from .errors import MissingProtocolUnitError, ProtocolUnitFailureError +from .errors import MissingUnitResultError, ProtocolUnitFailureError from .protocolunit import Context, ProtocolUnit, ProtocolUnitFailure, ProtocolUnitResult @@ -212,7 +212,7 @@ def unit_to_result(self, protocol_unit: ProtocolUnit) -> ProtocolUnitResult: Raises ------ - MissingProtocolUnitError: + MissingUnitResultError: if there are no results for that protocol unit ProtocolUnitFailureError: if all units failed @@ -220,7 +220,7 @@ def unit_to_result(self, protocol_unit: ProtocolUnit) -> ProtocolUnitResult: try: units = self._unit_result_mapping[protocol_unit] except KeyError: - raise MissingProtocolUnitError(f"No such `protocol_unit`:{protocol_unit} present") + raise MissingUnitResultError(f"No such `protocol_unit`:{protocol_unit} present") else: for u in units: if u.ok(): @@ -238,19 +238,19 @@ def unit_to_all_results(self, protocol_unit: ProtocolUnit) -> list[ProtocolUnitR Raises ------ - MissingProtocolUnitError + MissingUnitResultError if no results present for a given unit """ try: return self._unit_result_mapping[protocol_unit] except KeyError: - raise MissingProtocolUnitError(f"No such `protocol_unit`:{protocol_unit} present") + raise MissingUnitResultError(f"No such `protocol_unit`:{protocol_unit} present") def result_to_unit(self, protocol_unit_result: ProtocolUnitResult) -> ProtocolUnit: try: return self._result_unit_mapping[protocol_unit_result] except KeyError: - raise MissingProtocolUnitError(f"No such `protocol_unit_result`:{protocol_unit_result} present") + raise MissingUnitResultError(f"No such `protocol_unit_result`:{protocol_unit_result} present") def ok(self) -> bool: # ensure that for every protocol unit, there is an OK result object diff --git a/gufe/tests/test_protocol.py b/gufe/tests/test_protocol.py index 14820d4b..2294b422 100644 --- a/gufe/tests/test_protocol.py +++ b/gufe/tests/test_protocol.py @@ -24,7 +24,7 @@ ProtocolUnit, ProtocolUnitFailure, ProtocolUnitResult, - MissingProtocolUnitError, + MissingUnitResultError, ProtocolUnitFailureError ) from gufe.protocols.protocoldag import execute_DAG @@ -723,11 +723,11 @@ def test_foreign_objects(self, units, successes): transformation_key=None, ) - with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit`:NoDepUnit\(None\) present"): + with pytest.raises(MissingUnitResultError, match="No such `protocol_unit`:NoDepUnit\(None\) present"): dagresult.unit_to_result(units[2]) - with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit`:NoDepUnit\(None\) present"): + with pytest.raises(MissingUnitResultError, match="No such `protocol_unit`:NoDepUnit\(None\) present"): dagresult.unit_to_all_results(units[2]) - with pytest.raises(MissingProtocolUnitError, match="No such `protocol_unit_result`:ProtocolUnitResult\(None\) present"): + with pytest.raises(MissingUnitResultError, match="No such `protocol_unit_result`:ProtocolUnitResult\(None\) present"): dagresult.result_to_unit(successes[2])