Skip to content

Commit bc88833

Browse files
Improvement
1 parent 8f73ab5 commit bc88833

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

python/restate/exceptions.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,22 @@ def __init__(self, message: str) -> None:
2727
super().__init__(
2828
message +
2929
"""
30-
This exception should be ignored in your code. If you see this exception:
30+
This exception is safe to ignore. If you see it, you might be using a try/catch all statement.
3131
32-
* You might be using a try/catch all statement and logging afterwards. Don't do:
32+
Don't do:
3333
try:
3434
# Code
3535
except:
3636
# This catches all exceptions, including the SdkInternalBaseException!
37-
traceback.print_exc() <- Prints this exception
3837
3938
Do instead:
4039
try:
4140
# Code
4241
except TerminalError:
4342
# In Restate handlers you typically want to catch TerminalError only
4443
45-
* To catch ctx.run/ctx.run_typed errors, check https://docs.restate.dev/develop/python/durable-steps#run for more details.
46-
47-
* Only if you need to release/cleanup some resource, like a file,
48-
use try/finally https://docs.python.org/3/tutorial/errors.html#defining-clean-up-actions,
49-
or use restate.is_internal_exception to distinguish between an internal exception or not:
50-
51-
try:
52-
# Code
53-
except TerminalError:
54-
# Handle terminal error
55-
finally:
56-
# Perform cleanup
44+
Or remove the try/except altogether if you don't need it.
45+
For further info on error handling, refer to https://docs.restate.dev/develop/python/error-handling
5746
""")
5847

5948
class SuspendedException(SdkInternalBaseException):

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ impl ErrorFormatter for PythonErrorFormatter {
784784
fn display_closed_error(&self, f: &mut fmt::Formatter<'_>, event: &str) -> fmt::Result {
785785
write!(f, "Execution is suspended, but the handler is still attempting to make progress (calling '{event}'). This can happen:
786786
787-
* If you use catch all statements. Don't do:
787+
* If you use try/catch all statements.
788+
Don't do:
788789
try:
789790
# Code
790791
except:
@@ -797,7 +798,8 @@ try:
797798
except TerminalError:
798799
# In Restate handlers you typically want to catch TerminalError only
799800
800-
* To catch ctx.run/ctx.run_typed errors, check https://docs.restate.dev/develop/python/durable-steps#run for more details.
801+
Or remove the try/except altogether if you don't need it.
802+
For further info on error handling, refer to https://docs.restate.dev/develop/python/error-handling
801803
802804
* If you use the context after the handler completed, e.g. moving the context to another thread.
803805
Check https://docs.restate.dev/develop/python/concurrent-tasks for more details on how to create durable concurrent tasks in Python.")

0 commit comments

Comments
 (0)