Skip to content

Commit

Permalink
Centralize location of serialization/deserialization errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chris-janidlo committed Nov 16, 2023
1 parent 23a90f1 commit e6d040c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 32 deletions.
4 changes: 4 additions & 0 deletions compute_sdk/globus_compute_sdk/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .error_types import (
ComputeError,
DeserializationError,
MaxResultSizeExceeded,
SerdeError,
SerializationError,
TaskExecutionFailed,
TaskPending,
Expand All @@ -11,7 +13,9 @@
"ComputeError",
"TaskExecutionFailed",
"MaxResultSizeExceeded",
"SerdeError",
"SerializationError",
"DeserializationError",
"TaskPending",
"VersionMismatch",
)
24 changes: 19 additions & 5 deletions compute_sdk/globus_compute_sdk/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 2 additions & 16 deletions compute_sdk/globus_compute_sdk/serialize/base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}"
7 changes: 2 additions & 5 deletions compute_sdk/globus_compute_sdk/serialize/concretes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
7 changes: 2 additions & 5 deletions compute_sdk/globus_compute_sdk/serialize/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion compute_sdk/tests/integration/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6d040c

Please sign in to comment.