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
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ doc = false
[dependencies]
pyo3 = { version = "0.25.1", features = ["extension-module"] }
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
restate-sdk-shared-core = { version = "=0.6.0", features = ["request_identity", "sha2_random_seed"] }
restate-sdk-shared-core = { git = "https://github.com/restatedev/sdk-shared-core.git", rev = "eafbe4729a4ae7fa74fd0fb32e29121b240e1e5e", features = ["request_identity", "sha2_random_seed"] }
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use pyo3::create_exception;
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyNone, PyString};
Expand All @@ -7,6 +8,7 @@ use restate_sdk_shared_core::{
TerminalFailure, VMOptions, Value, CANCEL_NOTIFICATION_HANDLE, VM,
};
use std::time::{Duration, SystemTime};
use restate_sdk_shared_core::fmt::{set_error_formatter, ErrorFormatter};

// Current crate version
const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -158,6 +160,7 @@ impl From<PyFailure> for TerminalFailure {
TerminalFailure {
code: value.code,
message: value.message,
metadata: vec![],
}
}
}
Expand Down Expand Up @@ -751,6 +754,31 @@ impl PyIdentityVerifier {
}
}

#[derive(Debug)]
struct PythonErrorFormatter;

impl ErrorFormatter for PythonErrorFormatter {
fn display_closed_error(&self, f: &mut fmt::Formatter<'_>, event: &str) -> fmt::Result {
write!(f, "Execution is suspended, but the handler is still attempting to make progress (calling '{event}'). This can happen:

* If the SuspendedException is caught. Make sure you NEVER catch the SuspendedException, e.g. avoid:
try:
# Code
except:
# This catches all exceptions, including the SuspendedException!

And use instead:
try:
# Code
except TerminalException:
# In Restate handlers you typically want to catch TerminalException

Check https://docs.restate.dev/develop/python/durable-steps#run for more details on run error handling.

* If you use the context after the handler completed, e.g. moving the context to another thread. Check https://docs.restate.dev/develop/python/concurrent-tasks for more details on how to create durable concurrent tasks in Python.")
}
}

#[pymodule]
fn _internal(m: &Bound<'_, PyModule>) -> PyResult<()> {
use tracing_subscriber::EnvFilter;
Expand Down Expand Up @@ -790,5 +818,9 @@ fn _internal(m: &Bound<'_, PyModule>) -> PyResult<()> {
"CANCEL_NOTIFICATION_HANDLE",
PyNotificationHandle::from(CANCEL_NOTIFICATION_HANDLE),
)?;

// Set customized error formatter
set_error_formatter(PythonErrorFormatter);

Ok(())
}