From e6d040cc41bf506719c1b814faa4974b506b20aa Mon Sep 17 00:00:00 2001 From: Chris Janidlo Date: Wed, 15 Nov 2023 13:12:03 -0700 Subject: [PATCH] Centralize location of serialization/deserialization errors When implementing user-definable serialization, we were still using our original forked HighThroughputExecutor. That executor relied on globus_compute_sdk.errors.SerializationError. At the same time, the serialization module relied on its own SerializationError. To avoid mixing their semantics up, I left them in place. Now that we've moved away from HighThroughputExecutor, we no longer need that differentiation, so for consistency's sake, this moves the ser/de errors into the SDK's common errors module. At the same time, introduce a base class to catch both serialization and deserialization errors, and ensure that all three error classes are also ComputeErrors. --- .../globus_compute_sdk/errors/__init__.py | 4 ++++ .../globus_compute_sdk/errors/error_types.py | 24 +++++++++++++++---- .../globus_compute_sdk/serialize/base.py | 18 ++------------ .../globus_compute_sdk/serialize/concretes.py | 7 ++---- .../globus_compute_sdk/serialize/facade.py | 7 ++---- .../tests/integration/test_serialization.py | 3 ++- 6 files changed, 31 insertions(+), 32 deletions(-) diff --git a/compute_sdk/globus_compute_sdk/errors/__init__.py b/compute_sdk/globus_compute_sdk/errors/__init__.py index 7b17fb2d3..28063909a 100644 --- a/compute_sdk/globus_compute_sdk/errors/__init__.py +++ b/compute_sdk/globus_compute_sdk/errors/__init__.py @@ -1,6 +1,8 @@ from .error_types import ( ComputeError, + DeserializationError, MaxResultSizeExceeded, + SerdeError, SerializationError, TaskExecutionFailed, TaskPending, @@ -11,7 +13,9 @@ "ComputeError", "TaskExecutionFailed", "MaxResultSizeExceeded", + "SerdeError", "SerializationError", + "DeserializationError", "TaskPending", "VersionMismatch", ) diff --git a/compute_sdk/globus_compute_sdk/errors/error_types.py b/compute_sdk/globus_compute_sdk/errors/error_types.py index 2764fde8a..47c5d35f8 100644 --- a/compute_sdk/globus_compute_sdk/errors/error_types.py +++ b/compute_sdk/globus_compute_sdk/errors/error_types.py @@ -21,14 +21,28 @@ def __repr__(self): return f"Globus Compute Versioning Issue: {self.version_message}" -class SerializationError(ComputeError): - """Something failed during serialization or deserialization.""" +class SerdeError(ComputeError): + """Base class for SerializationError and DeserializationError""" - def __init__(self, message): - self.message = message + +class SerializationError(SerdeError): + """Something failed during serialization.""" + + def __init__(self, reason): + self.reason = reason + + def __repr__(self): + return f"Serialization failed due to {self.reason}" + + +class DeserializationError(SerdeError): + """Something failed during deserialization.""" + + def __init__(self, reason): + self.reason = reason def __repr__(self): - return f"Serialization Error during: {self.message}" + return f"Deserialization failed due to {self.reason}" class TaskPending(ComputeError): diff --git a/compute_sdk/globus_compute_sdk/serialize/base.py b/compute_sdk/globus_compute_sdk/serialize/base.py index d204fad70..9cb0f81d9 100644 --- a/compute_sdk/globus_compute_sdk/serialize/base.py +++ b/compute_sdk/globus_compute_sdk/serialize/base.py @@ -1,5 +1,7 @@ from abc import ABCMeta, abstractmethod +from globus_compute_sdk.errors import DeserializationError + class SerializationStrategy(metaclass=ABCMeta): """A SerializationStrategy is in charge of converting function source code or @@ -33,19 +35,3 @@ def serialize(self, data): @abstractmethod def deserialize(self, payload): raise NotImplementedError("Concrete class did not implement deserialize") - - -class SerializationError(Exception): - def __init__(self, reason): - self.reason = reason - - def __repr__(self): - return f"Serialization failed due to {self.reason}" - - -class DeserializationError(Exception): - def __init__(self, reason): - self.reason = reason - - def __repr__(self): - return f"Deserialization failed due to {self.reason}" diff --git a/compute_sdk/globus_compute_sdk/serialize/concretes.py b/compute_sdk/globus_compute_sdk/serialize/concretes.py index 0100addd6..bf68939ce 100644 --- a/compute_sdk/globus_compute_sdk/serialize/concretes.py +++ b/compute_sdk/globus_compute_sdk/serialize/concretes.py @@ -8,11 +8,8 @@ from collections import OrderedDict import dill -from globus_compute_sdk.serialize.base import ( - DeserializationError, - SerializationError, - SerializationStrategy, -) +from globus_compute_sdk.errors import DeserializationError, SerializationError +from globus_compute_sdk.serialize.base import SerializationStrategy logger = logging.getLogger(__name__) diff --git a/compute_sdk/globus_compute_sdk/serialize/facade.py b/compute_sdk/globus_compute_sdk/serialize/facade.py index 68e595a56..9f2a32389 100644 --- a/compute_sdk/globus_compute_sdk/serialize/facade.py +++ b/compute_sdk/globus_compute_sdk/serialize/facade.py @@ -3,11 +3,8 @@ import logging import typing as t -from globus_compute_sdk.serialize.base import ( - DeserializationError, - SerializationError, - SerializationStrategy, -) +from globus_compute_sdk.errors import DeserializationError, SerializationError +from globus_compute_sdk.serialize.base import SerializationStrategy from globus_compute_sdk.serialize.concretes import ( DEFAULT_STRATEGY_CODE, DEFAULT_STRATEGY_DATA, diff --git a/compute_sdk/tests/integration/test_serialization.py b/compute_sdk/tests/integration/test_serialization.py index 83dd9ec77..592fa9702 100644 --- a/compute_sdk/tests/integration/test_serialization.py +++ b/compute_sdk/tests/integration/test_serialization.py @@ -5,7 +5,8 @@ import globus_compute_sdk.serialize.concretes as concretes import pytest -from globus_compute_sdk.serialize.base import SerializationError, SerializationStrategy +from globus_compute_sdk.errors import SerializationError +from globus_compute_sdk.serialize.base import SerializationStrategy from globus_compute_sdk.serialize.facade import ComputeSerializer # length of serializer identifier