Skip to content

Commit

Permalink
Give some helpful info on a suspected serialization error
Browse files Browse the repository at this point in the history
Motivated by some requests in #help and by the fact that diagnosing and
fixing serialization-related errors is currently a rather arcane task.
  • Loading branch information
chris-janidlo authored and khk-globus committed Dec 12, 2023
1 parent aba6d45 commit ef3659a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
27 changes: 26 additions & 1 deletion compute_sdk/globus_compute_sdk/errors/error_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import re
import textwrap
import time

Expand Down Expand Up @@ -70,11 +71,31 @@ def __str__(self) -> str:
)


SERDE_TASK_EXECUTION_FAILED_HELP_MESSAGE = """
This appears to be an error with serialization. If it is, using a different
serialization strategy from globus_compute_sdk.serialize might resolve the issue. For
example, to use globus_compute_sdk.serialize.CombinedCode:
from globus_compute_sdk import Client, Executor
from globus_compute_sdk.serialize import CombinedCode
gcc = Client(code_serialization_strategy=CombinedCode())
with Executor('<your-endpoint-id>', client=gcc) as gcx:
# do something with gcx
For more information, see:
https://globus-compute.readthedocs.io/en/latest/sdk.html#specifying-a-serialization-strategy
"""


class TaskExecutionFailed(Exception):
"""
Error result from the remote end, wrapped as an exception object
"""

SERDE_REGEX = re.compile("dill|pickle|serializ", re.IGNORECASE)

def __init__(
self,
remote_data: str,
Expand All @@ -87,4 +108,8 @@ def __init__(
self.completion_t = completion_t or str(time.time())

def __str__(self) -> str:
return "\n" + textwrap.indent(self.remote_data, " ")
remote_data = textwrap.indent(self.remote_data, " ")
message = "\n" + remote_data
if re.search(TaskExecutionFailed.SERDE_REGEX, remote_data):
message += SERDE_TASK_EXECUTION_FAILED_HELP_MESSAGE
return message
27 changes: 27 additions & 0 deletions compute_sdk/tests/unit/test_error_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import traceback
from functools import lru_cache

import pytest
from globus_compute_sdk.errors import TaskExecutionFailed
from globus_compute_sdk.serialize import DillCodeSource


@lru_cache(maxsize=None)
def annotated_function():
return "data"


def test_task_execution_failed_serialization_help_msg():
try:
DillCodeSource().serialize(annotated_function)
except OSError:
tb = traceback.format_exc()
else:
pytest.fail("Expected DillCodeSource to fail to serialize annotated functions")

tef = TaskExecutionFailed(tb)
assert "This appears to be an error with serialization." in str(tef)
assert (
"https://globus-compute.readthedocs.io/en/latest/sdk.html"
"#specifying-a-serialization-strategy" in str(tef)
)

0 comments on commit ef3659a

Please sign in to comment.