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
4 changes: 2 additions & 2 deletions python/restate/server_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ async def enter(self):
cause = cause.__cause__
else:
# nothing interesting found, treat as unexpected exception
stacktrace = "\n".join(traceback.format_exception(e))
stacktrace = "".join(traceback.format_exception(e))
self.vm.notify_error(repr(e), stacktrace)
raise
finally:
Expand Down Expand Up @@ -680,7 +680,7 @@ async def create_run_coroutine(
except Exception as e:
end = time.time()
attempt_duration = int((end - start) * 1000)
failure = Failure(code=500, message=str(e))
failure = Failure(code=500, message=repr(e), stacktrace="".join(traceback.format_exception(e)))
max_duration_ms = None if max_duration is None else int(max_duration.total_seconds() * 1000)
initial_retry_interval_ms = (
None if initial_retry_interval is None else int(initial_retry_interval.total_seconds() * 1000)
Expand Down
3 changes: 2 additions & 1 deletion python/restate/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Failure:

code: int
message: str
stacktrace: typing.Optional[str] = None


@dataclass
Expand Down Expand Up @@ -433,7 +434,7 @@ def propose_run_completion_transient(
Exit a side effect with a transient Error.
This requires a retry policy to be provided.
"""
py_failure = PyFailure(failure.code, failure.message)
py_failure = PyFailure(failure.code, failure.message, failure.stacktrace)
py_config = PyExponentialRetryConfig(
config.initial_interval,
config.max_attempts,
Expand Down
51 changes: 39 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ struct PyFailure {
code: u16,
#[pyo3(get, set)]
message: String,
#[pyo3(get, set)]
stacktrace: Option<String>,
}

#[pymethods]
impl PyFailure {
#[new]
fn new(code: u16, message: String) -> PyFailure {
Self { code, message }
#[pyo3(signature = (code, message, stacktrace=None))]
fn new(code: u16, message: String, stacktrace: Option<String>) -> PyFailure {
Self {
code,
message,
stacktrace,
}
}
}

Expand Down Expand Up @@ -173,6 +180,7 @@ impl From<TerminalFailure> for PyFailure {
PyFailure {
code: value.code,
message: value.message,
stacktrace: None,
}
}
}
Expand All @@ -188,8 +196,18 @@ impl From<PyFailure> for TerminalFailure {
}

impl From<PyFailure> for Error {
fn from(value: PyFailure) -> Self {
Self::new(value.code, value.message)
fn from(
PyFailure {
code,
message,
stacktrace,
}: PyFailure,
) -> Self {
let mut e = Self::new(code, message);
if let Some(stacktrace) = stacktrace {
e = e.with_stacktrace(stacktrace);
}
e
}
}

Expand Down Expand Up @@ -501,7 +519,8 @@ impl PyVM {
.map(Into::into)
.collect(),
},
buffer.as_bytes().to_vec().into(),Default::default()
buffer.as_bytes().to_vec().into(),
Default::default(),
)
.map(Into::into)
.map_err(Into::into)
Expand Down Expand Up @@ -539,8 +558,8 @@ impl PyVM {
.duration_since(SystemTime::UNIX_EPOCH)
.expect("Duration since unix epoch cannot fail")
+ Duration::from_millis(millis)
})
, Default::default()
}),
Default::default(),
)
.map(|s| s.invocation_id_notification_handle.into())
.map_err(Into::into)
Expand All @@ -566,7 +585,7 @@ impl PyVM {
.sys_complete_awakeable(
id,
NonEmptyValue::Success(buffer.as_bytes().to_vec().into()),
Default::default()
Default::default(),
)
.map_err(Into::into)
}
Expand Down Expand Up @@ -613,7 +632,8 @@ impl PyVM {
.vm
.sys_complete_promise(
key,
NonEmptyValue::Success(buffer.as_bytes().to_vec().into()),Default::default()
NonEmptyValue::Success(buffer.as_bytes().to_vec().into()),
Default::default(),
)
.map(Into::into)
.map_err(Into::into)
Expand All @@ -626,7 +646,11 @@ impl PyVM {
) -> Result<PyNotificationHandle, PyVMError> {
self_
.vm
.sys_complete_promise(key, NonEmptyValue::Failure(value.into()),Default::default())
.sys_complete_promise(
key,
NonEmptyValue::Failure(value.into()),
Default::default(),
)
.map(Into::into)
.map_err(Into::into)
}
Expand Down Expand Up @@ -701,7 +725,10 @@ impl PyVM {
) -> Result<(), PyVMError> {
self_
.vm
.sys_write_output(NonEmptyValue::Success(buffer.as_bytes().to_vec().into()),Default::default())
.sys_write_output(
NonEmptyValue::Success(buffer.as_bytes().to_vec().into()),
Default::default(),
)
.map_err(Into::into)
}

Expand All @@ -711,7 +738,7 @@ impl PyVM {
) -> Result<(), PyVMError> {
self_
.vm
.sys_write_output(NonEmptyValue::Failure(value.into()),Default::default())
.sys_write_output(NonEmptyValue::Failure(value.into()), Default::default())
.map_err(Into::into)
}

Expand Down