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