Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/aws_durable_execution_sdk_python/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from threading import Lock
from typing import TYPE_CHECKING

from aws_durable_execution_sdk_python.exceptions import DurableExecutionsError
from aws_durable_execution_sdk_python.exceptions import (
CallableRuntimeError,
)
from aws_durable_execution_sdk_python.lambda_service import (
CheckpointOutput,
DurableServiceClient,
Expand Down Expand Up @@ -140,10 +142,18 @@ def is_replay_children(self) -> bool:
return False
return op.context_details.replay_children if op.context_details else False

def raise_callable_error(self) -> None:
def raise_callable_error(self, msg: str | None = None) -> None:
if self.error is None:
msg: str = "Attempted to throw exception, but no ErrorObject exists on the Checkpoint Operation."
raise DurableExecutionsError(msg)
err_msg = (
msg
or "Unknown error. No ErrorObject exists on the Checkpoint Operation."
)
raise CallableRuntimeError(
message=err_msg,
error_type=None,
data=None,
stack_trace=None,
)

raise self.error.to_callable_runtime_error()

Expand Down
14 changes: 12 additions & 2 deletions tests/state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import pytest

from aws_durable_execution_sdk_python.exceptions import DurableExecutionsError
from aws_durable_execution_sdk_python.exceptions import (
CallableRuntimeError,
)
from aws_durable_execution_sdk_python.lambda_service import (
CallbackDetails,
ChainedInvokeDetails,
Expand Down Expand Up @@ -325,10 +327,18 @@ def test_checkpointed_result_raise_callable_error_no_error():
"""Test CheckpointedResult.raise_callable_error with no error."""
result = CheckpointedResult()

with pytest.raises(DurableExecutionsError, match="no ErrorObject exists"):
with pytest.raises(CallableRuntimeError, match="Unknown error"):
result.raise_callable_error()


def test_checkpointed_result_raise_callable_error_no_error_with_message():
"""Test CheckpointedResult.raise_callable_error with no error and custom message."""
result = CheckpointedResult()

with pytest.raises(CallableRuntimeError, match="Custom error message"):
result.raise_callable_error("Custom error message")


def test_checkpointed_result_immutable():
"""Test that CheckpointedResult is immutable."""
result = CheckpointedResult(status=OperationStatus.SUCCEEDED)
Expand Down
Loading