From 6c51879768d756ee4c1476b65456f4089635639b Mon Sep 17 00:00:00 2001 From: Aaron Harper Date: Fri, 3 Nov 2023 13:34:42 -0400 Subject: [PATCH] Handle error; add CallError.original_error --- inngest/_internal/comm.py | 11 ++++++++++- inngest/_internal/execution.py | 4 ++++ inngest/_internal/net.py | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/inngest/_internal/comm.py b/inngest/_internal/comm.py index 3fb72f7c..8e59ede9 100644 --- a/inngest/_internal/comm.py +++ b/inngest/_internal/comm.py @@ -338,7 +338,16 @@ def call_function_sync( if isinstance(call_res, execution.FunctionCallResponse): # Only call this hook if we get a return at the function # level. - middleware.after_execution_sync() + match middleware.after_execution_sync(): + case result.Ok(_): + pass + case result.Err(err): + middleware.before_response_sync() + return CommResponse.from_error( + self._client.logger, + self._framework, + err, + ) comm_res = CommResponse.from_call_result( self._client.logger, diff --git a/inngest/_internal/execution.py b/inngest/_internal/execution.py index b8b1f123..b6409760 100644 --- a/inngest/_internal/execution.py +++ b/inngest/_internal/execution.py @@ -4,6 +4,8 @@ import enum import typing +import pydantic + from . import errors, event_lib, transforms, types @@ -39,6 +41,7 @@ class CallError(types.BaseModel): is_retriable: bool message: str name: str + original_error: object = pydantic.Field(exclude=True) stack: str @classmethod @@ -48,6 +51,7 @@ def from_error(cls, err: Exception) -> CallError: is_retriable=isinstance(err, errors.NonRetriableError) is False, message=str(err), name=type(err).__name__, + original_error=err, stack=transforms.get_traceback(err), ) diff --git a/inngest/_internal/net.py b/inngest/_internal/net.py index 5d31a783..05ce6cd7 100644 --- a/inngest/_internal/net.py +++ b/inngest/_internal/net.py @@ -14,8 +14,8 @@ def create_headers( ) -> dict[str, str]: headers = { const.HeaderKey.CONTENT_TYPE.value: "application/json", - const.HeaderKey.USER_AGENT.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}", const.HeaderKey.SDK.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}", + const.HeaderKey.USER_AGENT.value: f"inngest-{const.LANGUAGE}:v{const.VERSION}", } if framework is not None: