Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added notes to ApplicationError and FailureError exception docstrings. #718

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
51 changes: 48 additions & 3 deletions temporalio/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
"""Common Temporal exceptions."""
"""Common Temporal exceptions.

# Temporal Failure

Most Temporal SDKs have a base class that the other Failures extend.
In python, it is the ``FailureError``.

# Application Failure

Workflow, and Activity, and Nexus Operation code use Application Failures to
communicate application-specific failures that happen.
This is the only type of Temporal Failure created and thrown by user code.
In the Python SDK, it is the ``ApplicationError``.

# References

More information can be found in the docs at
https://docs.temporal.io/references/failures#workflow-execution-failures.
"""

import asyncio
from datetime import timedelta
Expand All @@ -23,7 +41,15 @@ def cause(self) -> Optional[BaseException]:


class FailureError(TemporalError):
"""Base for runtime failures during workflow/activity execution."""
"""Base for runtime failures during workflow/activity execution.

This is extended by ``ApplicationError``, which can be raised in a Workflow to fail the Workflow Execution.
Workflow Execution Failures put the Workflow Execution into the "Failed" state and no more attempts will
be made in progressing this execution.

Any exception that does not extend this exception
is considered a Workflow Task Failure. These types of failures will cause the Workflow Task to be retried.
"""
Copy link
Member

@cretz cretz Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually more complicated than this since it is now configurable. We dedicate a section of our README to this at https://github.com/temporalio/sdk-python?tab=readme-ov-file#exceptions. Ideally we don't have to duplicate so much in here and there considering they may not say the same things, as is the case already here where it is not explained that this is customizable.


GSmithApps marked this conversation as resolved.
Show resolved Hide resolved
def __init__(
self,
Expand Down Expand Up @@ -71,7 +97,26 @@ def __init__(


class ApplicationError(FailureError):
"""Error raised during workflow/activity execution."""
"""Error raised during workflow/activity execution.

Can be raised in a Workflow to fail the Workflow Execution.
Workflow Execution Failures put the Workflow Execution into the "Failed" state and no more attempts will
be made in progressing their execution.

If you are creating custom exceptions or raising typical Python-based
exceptions you would either need to extend this class or
explicitly state that the exception is a Workflow Execution Failure by raising a new ``ApplicationError``.

Any exception that does not extend this exception
is considered a Workflow Task Failure. These types of failures will cause the Workflow Task to be retried.

GSmithApps marked this conversation as resolved.
Show resolved Hide resolved
# Example

>>> from temporalio.exceptions import ApplicationError
... # ...
... if isDelivery and distance.get_kilometers() > 25:
... raise ApplicationError("Customer lives outside the service area")
"""

def __init__(
self,
Expand Down
Loading