Azure / azure-functions-durable-python

Python library for using the Durable Functions bindings.
MIT License
134 stars 51 forks source link

Errors in Activity Functions cannot be handled using try...except #496

Open danielniccoli opened 2 months ago

danielniccoli commented 2 months ago

πŸ› Describe the bug

I cannot catch an error thrown inside an activity function in the orchestrator.

πŸ€” Expected behavior

The error should have been caught and handled by the except in the orchestrator function.

β˜• Steps to reproduce

import azure.functions as func
import azure.durable_functions as df

myApp = df.DFApp(http_auth_level=func.AuthLevel.ANONYMOUS)

# An HTTP-Triggered Function with a Durable Functions Client binding
@myApp.route(route="orchestrators/{functionName}")
@myApp.durable_client_input(client_name="client")
async def http_start(req: func.HttpRequest, client):
    function_name = req.route_params.get('functionName')
    instance_id = await client.start_new(function_name)
    response = client.create_check_status_response(req, instance_id)
    return response

# Orchestrator
@myApp.orchestration_trigger(context_name="context")
def hello_orchestrator(context):
    result1 = yield context.call_activity("hello", "Seattle")
    try:
        result2 = yield context.call_activity("hello", "Tokyo")
    except ValueError:
        result2 = "An error was thrown!"
    result3 = yield context.call_activity("hello", "London")

    return [result1, result2, result3]

# Activity
@myApp.activity_trigger(input_name="city")
def hello(city: str):
    if (city=="Tokyo"):
        raise ValueError("This error is thrown on purpose!")
    return f"Hello {city}"

Logs


 *  Executing task: .venv\Scripts\python -m pip install -r requirements.txt 

Requirement already satisfied: azure-functions in c:\code\sample_df_error_handling\.venv\lib\site-packages (from -r requirements.txt (line 1)) (1.19.0)
Requirement already satisfied: azure-functions-durable in c:\code\sample_df_error_handling\.venv\lib\site-packages (from -r requirements.txt (line 2)) (1.2.9)
Requirement already satisfied: aiohttp>=3.6.2 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 2)) (3.9.5)
Requirement already satisfied: requests==2.* in c:\code\sample_df_error_handling\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 2)) (2.31.0)
Requirement already satisfied: python-dateutil>=2.8.0 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 2)) (2.9.0.post0)
Requirement already satisfied: furl>=2.1.0 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from azure-functions-durable->-r requirements.txt (line 2)) (2.1.3)
Requirement already satisfied: charset-normalizer<4,>=2 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 2)) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 2)) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 2)) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from requests==2.*->azure-functions-durable->-r requirements.txt (line 2)) (2024.2.2)
Requirement already satisfied: aiosignal>=1.1.2 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 2)) (1.3.1)
Requirement already satisfied: attrs>=17.3.0 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 2)) (23.2.0)
Requirement already satisfied: frozenlist>=1.1.1 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 2)) (1.4.1)
Requirement already satisfied: multidict<7.0,>=4.5 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 2)) (6.0.5)
Requirement already satisfied: yarl<2.0,>=1.0 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from aiohttp>=3.6.2->azure-functions-durable->-r requirements.txt (line 2)) (1.9.4)
Requirement already satisfied: six>=1.8.0 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from furl>=2.1.0->azure-functions-durable->-r requirements.txt (line 2)) (1.16.0)
Requirement already satisfied: orderedmultidict>=1.0.1 in c:\code\sample_df_error_handling\.venv\lib\site-packages (from furl>=2.1.0->azure-functions-durable->-r requirements.txt (line 2)) (1.0.1)
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: .venv\Scripts\activate ; func host start 

Found Python version 3.11.8 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

[2024-04-29T10:26:16.533Z] 0.01s - Debugger warning: It seems that frozen modules are being used, which may
[2024-04-29T10:26:16.535Z] 0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
[2024-04-29T10:26:16.536Z] 0.00s - to python to disable frozen modules.
[2024-04-29T10:26:16.537Z] 0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[2024-04-29T10:26:16.619Z] Worker process started and initialized.

Functions:

        http_start:  http://localhost:7071/api/orchestrators/{functionName}

        hello: activityTrigger

        hello_orchestrator: orchestrationTrigger

For detailed output, run func with --verbose flag.
[2024-04-29T10:26:20.356Z] Executing 'Functions.http_start' (Reason='This function was programmatically called via the host APIs.', Id=a00c3fc4-cfa3-49f0-b2ba-0252d517ed35)
[2024-04-29T10:26:20.565Z] Executed 'Functions.http_start' (Succeeded, Id=a00c3fc4-cfa3-49f0-b2ba-0252d517ed35, Duration=222ms)
[2024-04-29T10:26:21.577Z] Host lock lease acquired by instance ID '00000000000000000000000067BB950F'.
[2024-04-29T10:26:22.144Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=21fa0dea-398a-4e1d-834f-da269fd352ca)
[2024-04-29T10:26:22.187Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=21fa0dea-398a-4e1d-834f-da269fd352ca, Duration=46ms)
[2024-04-29T10:26:22.234Z] Executing 'Functions.hello' (Reason='(null)', Id=c48ab672-43c7-4d31-a266-de35b1336efc)
[2024-04-29T10:26:22.240Z] Executed 'Functions.hello' (Succeeded, Id=c48ab672-43c7-4d31-a266-de35b1336efc, Duration=7ms)
[2024-04-29T10:26:22.276Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=4a52de25-4167-473c-8ea1-9dbd6652ff64)
[2024-04-29T10:26:22.286Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=4a52de25-4167-473c-8ea1-9dbd6652ff64, Duration=11ms)
[2024-04-29T10:26:22.305Z] Executing 'Functions.hello' (Reason='(null)', Id=b8c0bf09-cbb1-4613-9299-1a88842f25fd)
[2024-04-29T10:26:22.323Z] Executed 'Functions.hello' (Failed, Id=b8c0bf09-cbb1-4613-9299-1a88842f25fd, Duration=16ms)
[2024-04-29T10:26:22.325Z] System.Private.CoreLib: Exception while executing function: Functions.hello. System.Private.CoreLib: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")
.
[2024-04-29T10:26:22.334Z] 2ff6c54c48ea407ca5a2f4fbbfc3920f: Function 'hello (Activity)' failed with an error. Reason: System.Exception:  ValueError: This error is thrown on purpose!
[2024-04-29T10:26:22.335Z]  ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")

[2024-04-29T10:26:22.337Z]    at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101
[2024-04-29T10:26:22.338Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
[2024-04-29T10:26:22.338Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
[2024-04-29T10:26:22.339Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
[2024-04-29T10:26:22.340Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 581
[2024-04-29T10:26:22.340Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 527
[2024-04-29T10:26:22.341Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 306
[2024-04-29T10:26:22.341Z]    --- End of inner exception stack trace ---. IsReplay: False. State: Failed. RuntimeStatus: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 12. TaskEventId: 1
[2024-04-29T10:26:22.373Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=26d5bb22-3b4d-414d-a42e-abf0e81f3848)
[2024-04-29T10:26:22.395Z] 2ff6c54c48ea407ca5a2f4fbbfc3920f: Function 'hello_orchestrator (Orchestrator)' failed with an error. Reason: Message: Activity function 'hello' failed:  ValueError: This error is thrown on purpose! 
 {"$type":"System.Exception, System.Private.CoreLib","ClassName":"System.Exception","Message":" ValueError: This error is thrown on purpose!","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException, Microsoft.Azure.WebJobs.Script","IsUserException":false,"RemoteStackTrace":"  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","RemoteMessage":"ValueError: This error is thrown on purpose!","RemoteTypeName":null,"Message":"Result: Failure\nException: ValueError: This error is thrown on purpose!\nStack:   File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","Data":{"$type":"System.Collections.ListDictionaryInternal, System.Private.CoreLib"},"InnerException":null,"HelpLink":null,"Source":"System.Private.CoreLib","HResult":-2146233088,"StackTrace":"   at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionInvoker.cs:line 52\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 581\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 527\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 306"},"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":null,"WatsonBuckets":null}, StackTrace:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2024-04-29T10:26:22.398Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2024-04-29T10:26:22.399Z]    at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskOrchestrationShim.InvokeUserCodeAndHandleResults(RegisteredFunctionInfo orchestratorInfo, OrchestrationContext innerContext) in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskOrchestrationShim.cs:line 150. IsReplay: False. State: Failed. RuntimeStatus: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 13. TaskEventId: -1
[2024-04-29T10:26:22.415Z] Executed 'Functions.hello_orchestrator' (Failed, Id=26d5bb22-3b4d-414d-a42e-abf0e81f3848, Duration=27ms)
[2024-04-29T10:26:22.416Z] System.Private.CoreLib: Exception while executing function: Functions.hello_orchestrator. Microsoft.Azure.WebJobs.Extensions.DurableTask: Orchestrator function 'hello_orchestrator' failed: Activity function 'hello' failed:  ValueError: This error is thrown on purpose!
 {"$type":"System.Exception, System.Private.CoreLib","ClassName":"System.Exception","Message":" ValueError: This error is thrown on purpose!","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException, Microsoft.Azure.WebJobs.Script","IsUserException":false,"RemoteStackTrace":"  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","RemoteMessage":"ValueError: This error is thrown on purpose!","RemoteTypeName":null,"Message":"Result: Failure\nException: ValueError: This error is thrown on purpose!\nStack:   File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","Data":{"$type":"System.Collections.ListDictionaryInternal, System.Private.CoreLib"},"InnerException":null,"HelpLink":null,"Source":"System.Private.CoreLib","HResult":-2146233088,"StackTrace":"   at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionInvoker.cs:line 52\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 581\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 527\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 306"},"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":null,"WatsonBuckets":null}.
[2024-04-29T10:28:11.195Z] Executing 'Functions.hello' (Reason='(null)', Id=b2c5c8c4-b9c9-4b8a-b259-e43899dbd177)
[2024-04-29T10:28:11.207Z] Executed 'Functions.hello' (Failed, Id=b2c5c8c4-b9c9-4b8a-b259-e43899dbd177, Duration=11ms)
[2024-04-29T10:28:11.210Z] System.Private.CoreLib: Exception while executing function: Functions.hello. System.Private.CoreLib: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")
.
[2024-04-29T10:28:11.213Z] d0bc89db4a384d89a8d768343cb470cf: Function 'hello (Activity)' failed with an error. Reason: System.Exception:  ValueError: This error is thrown on purpose!
[2024-04-29T10:28:11.214Z]  ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")

[2024-04-29T10:28:11.216Z]    at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101
[2024-04-29T10:28:11.217Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
[2024-04-29T10:28:11.217Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
[2024-04-29T10:28:11.218Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
[2024-04-29T10:28:11.219Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 581
[2024-04-29T10:28:11.220Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 527
[2024-04-29T10:28:11.221Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 306
[2024-04-29T10:28:11.222Z]    --- End of inner exception stack trace ---. IsReplay: False. State: Failed. RuntimeStatus: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 15. TaskEventId: 1
[2024-04-29T10:28:11.258Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=3d66c0d1-1d44-4770-a248-201f8785dfae)
[2024-04-29T10:28:11.266Z] d0bc89db4a384d89a8d768343cb470cf: Function 'hello_orchestrator (Orchestrator)' failed with an error. Reason: Message: Activity function 'hello' failed:  ValueError: This error is thrown on purpose!
 {"$type":"System.Exception, System.Private.CoreLib","ClassName":"System.Exception","Message":" ValueError: This error is thrown on purpose!","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException, Microsoft.Azure.WebJobs.Script","IsUserException":false,"RemoteStackTrace":"  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","RemoteMessage":"ValueError: This error is thrown on purpose!","RemoteTypeName":null,"Message":"Result: Failure\nException: ValueError: This error is thrown on purpose!\nStack:   File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","Data":{"$type":"System.Collections.ListDictionaryInternal, System.Private.CoreLib"},"InnerException":null,"HelpLink":null,"Source":"System.Private.CoreLib","HResult":-2146233088,"StackTrace":"   at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionInvoker.cs:line 52\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 581\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 527\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 306"},"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":null,"WatsonBuckets":null}, StackTrace:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
[2024-04-29T10:28:11.270Z]    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
[2024-04-29T10:28:11.270Z]    at Microsoft.Azure.WebJobs.Extensions.DurableTask.TaskOrchestrationShim.InvokeUserCodeAndHandleResults(RegisteredFunctionInfo orchestratorInfo, OrchestrationContext innerContext) in D:\a\_work\1\s\src\WebJobs.Extensions.DurableTask\Listener\TaskOrchestrationShim.cs:line 150. IsReplay: False. State: Failed. RuntimeStatus: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 16. TaskEventId: -1
[2024-04-29T10:28:11.272Z] Executed 'Functions.hello_orchestrator' (Failed, Id=3d66c0d1-1d44-4770-a248-201f8785dfae, Duration=14ms)
[2024-04-29T10:28:11.273Z] System.Private.CoreLib: Exception while executing function: Functions.hello_orchestrator. Microsoft.Azure.WebJobs.Extensions.DurableTask: Orchestrator function 'hello_orchestrator' failed: Activity function 'hello' failed:  ValueError: This error is thrown on purpose!
 {"$type":"System.Exception, System.Private.CoreLib","ClassName":"System.Exception","Message":" ValueError: This error is thrown on purpose!","Data":null,"InnerException":{"$type":"Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException, Microsoft.Azure.WebJobs.Script","IsUserException":false,"RemoteStackTrace":"  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","RemoteMessage":"ValueError: This error is thrown on purpose!","RemoteTypeName":null,"Message":"Result: Failure\nException: ValueError: This error is thrown on purpose!\nStack:   File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 505, in _handle__invocation_request\n    call_result = await self._loop.run_in_executor(\n                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Users\\niccodan\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\concurrent\\futures\\thread.py\", line 58, in run\n    result = self.fn(*self.args, **self.kwargs)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\dispatcher.py\", line 778, in _run_sync_func\n    return ExtensionManager.get_sync_invocation_wrapper(context,\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"C:\\Program Files\\Microsoft\\Azure Functions Core Tools\\workers\\python\\3.11/WINDOWS/X64\\azure_functions_worker\\extension.py\", line 215, in _raw_invocation_wrapper\n    result = function(**args)\n             ^^^^^^^^^^^^^^^^\n  File \"C:\\code\\sample_df_error_handling\\function_app.py\", line 31, in hello\n    raise ValueError(\"This error is thrown on purpose!\")\n","Data":{"$type":"System.Collections.ListDictionaryInternal, System.Private.CoreLib"},"InnerException":null,"HelpLink":null,"Source":"System.Private.CoreLib","HResult":-2146233088,"StackTrace":"   at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82\r\n   at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionInvoker.cs:line 52\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 581\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 527\r\n   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\\a\\_work\\1\\s\\src\\Microsoft.Azure.WebJobs.Host\\Executors\\FunctionExecutor.cs:line 306"},"HelpURL":null,"StackTraceString":null,"RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233088,"Source":null,"WatsonBuckets":null}.

 *  The terminal process "C:\Program Files\PowerShell\7\pwsh.exe -Command .venv\Scripts\activate ; func host start" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 
 * ```
cgillum commented 2 months ago

I'm not a Python expert, but could it be that the ValueError type information isn't being preserved, causing the except block to be skipped?

I ask because looking at the documentation here, it shows an except block but without a specific error type.

I'm specifically wondering if this might work:

# Orchestrator
@myApp.orchestration_trigger(context_name="context")
def hello_orchestrator(context):
    result1 = yield context.call_activity("hello", "Seattle")
    try:
        result2 = yield context.call_activity("hello", "Tokyo")
    except: # handle all error types
        result2 = "An error was thrown!"
    result3 = yield context.call_activity("hello", "London")

    return [result1, result2, result3]
danielniccoli commented 2 months ago

Yes, I can confirm that except Exception as e: does catch the error and it is of type Exception, instead of type ValueError.

Here are the logs:

Executing task: .venv\Scripts\activate ; func host start 

Found Python version 3.11.8 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5611 Commit hash: N/A +591b8aec842e333a87ea9e23ba390bb5effe0655 (64-bit)
Function Runtime Version: 4.31.1.22191

[2024-05-02T08:27:23.874Z] 0.01s - Debugger warning: It seems that frozen modules are being used, which may
[2024-05-02T08:27:23.875Z] 0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
[2024-05-02T08:27:23.876Z] 0.00s - to python to disable frozen modules.
[2024-05-02T08:27:23.878Z] 0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.
[2024-05-02T08:27:23.966Z] Worker process started and initialized.

Functions:

        http_start:  http://localhost:7071/api/orchestrators/{functionName}

        hello: activityTrigger

        hello_orchestrator: orchestrationTrigger

For detailed output, run func with --verbose flag.
[2024-05-02T08:27:28.941Z] Host lock lease acquired by instance ID '00000000000000000000000067BB950F'.
[2024-05-02T08:27:51.568Z] Executing 'Functions.http_start' (Reason='This function was programmatically called via the host APIs.', Id=39efaa79-e648-4acc-ad3f-992132aaa7e7)
[2024-05-02T08:27:51.767Z] Executed 'Functions.http_start' (Succeeded, Id=39efaa79-e648-4acc-ad3f-992132aaa7e7, Duration=216ms)
[2024-05-02T08:27:51.790Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=d27703e7-cb42-4fd6-bb1f-6f66dbfb2fa1)
[2024-05-02T08:27:51.827Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=d27703e7-cb42-4fd6-bb1f-6f66dbfb2fa1, Duration=41ms)
[2024-05-02T08:27:51.870Z] Executing 'Functions.hello' (Reason='(null)', Id=1b393e57-623d-4160-9f73-b6bf9a9175f2)
[2024-05-02T08:27:51.874Z] Executed 'Functions.hello' (Succeeded, Id=1b393e57-623d-4160-9f73-b6bf9a9175f2, Duration=5ms)
[2024-05-02T08:27:51.911Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=afbc774b-9033-4ec6-908f-f611d8822518)
[2024-05-02T08:27:51.922Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=afbc774b-9033-4ec6-908f-f611d8822518, Duration=11ms)
[2024-05-02T08:27:51.943Z] Executing 'Functions.hello' (Reason='(null)', Id=7a95903b-babb-4146-9d1c-13c17fb77265)
[2024-05-02T08:27:51.963Z] Executed 'Functions.hello' (Failed, Id=7a95903b-babb-4146-9d1c-13c17fb77265, Duration=18ms)
[2024-05-02T08:27:51.965Z] System.Private.CoreLib: Exception while executing function: Functions.hello. System.Private.CoreLib: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")
.
[2024-05-02T08:27:51.978Z] d371bfcf602a4b0fbe694770472d5d8e: Function 'hello (Activity)' failed with an error. Reason: System.Exception:  ValueError: This error is thrown on purpose!
[2024-05-02T08:27:51.979Z]  ---> Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException: Result: Failure
Exception: ValueError: This error is thrown on purpose!
Stack:   File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 505, in _handle__invocation_request
    call_result = await self._loop.run_executor(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\niccodan\AppData\Local\Programs\Python\Python311\Lib\concurrent\futures\thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\dispatcher.py", line 778, in _run_sync_func
    return ExtensionManager.get_sync_invocation_wrapper(context,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Microsoft\Azure Functions Core Tools\workers\python\3.11/WINDOWS/X64\azure_functions_worker\extension.py", line 215, in _raw_invocation_wrapper
    result = function(**args)
             ^^^^^^^^^^^^^^^^
  File "C:\code\sample_df_error_handling\function_app.py", line 31, in hello
    raise ValueError("This error is thrown on purpose!")

[2024-05-02T08:27:51.981Z]    at Microsoft.Azure.WebJobs.Script.Description.WorkerFunctionInvoker.InvokeCore(Object[] parameters, FunctionInvocationContext context) in /_/src/WebJobs.Script/Description/Workers/WorkerFunctionInvoker.cs:line 101
[2024-05-02T08:27:51.982Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionInvokerBase.Invoke(Object[] parameters) in /_/src/WebJobs.Script/Description/FunctionInvokerBase.cs:line 82
[2024-05-02T08:27:51.982Z]    at Microsoft.Azure.WebJobs.Script.Description.FunctionGenerator.Coerce[T](Task`1 src) in /_/src/WebJobs.Script/Description/FunctionGenerator.cs:line 225
[2024-05-02T08:27:51.983Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
[2024-05-02T08:27:51.984Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Boolean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 581
[2024-05-02T08:27:51.985Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 527
[2024-05-02T08:27:51.986Z]    at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 306
[2024-05-02T08:27:51.987Z]    --- End of inner exception stack trace ---. IsReplay: False. State: Failed. RuntimeStatus: Failed. HubName: TestHubName. AppName: . SlotName: . ExtensionVersion: 2.12.0. SequenceNumber: 12. TaskEventId: 1
[2024-05-02T08:27:52.027Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=b588f41c-46d2-4b3b-8270-0899046e1200)
[2024-05-02T08:27:52.043Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=b588f41c-46d2-4b3b-8270-0899046e1200, Duration=16ms)
[2024-05-02T08:27:52.062Z] Executing 'Functions.hello' (Reason='(null)', Id=3054a92a-16ce-44e4-9037-84075d7508f1)
[2024-05-02T08:27:52.066Z] Executed 'Functions.hello' (Succeeded, Id=3054a92a-16ce-44e4-9037-84075d7508f1, Duration=4ms)
[2024-05-02T08:27:52.086Z] Executing 'Functions.hello_orchestrator' (Reason='(null)', Id=47cd7f2f-a45d-4962-9673-db3ab6b23c8a)
[2024-05-02T08:27:52.096Z] Executed 'Functions.hello_orchestrator' (Succeeded, Id=47cd7f2f-a45d-4962-9673-db3ab6b23c8a, Duration=10ms)

Some notes

The orchestration completes with the runtime status of Completed (successfully).

{
  "name": "hello_orchestrator",
  "instanceId": "d371bfcf602a4b0fbe694770472d5d8e",
  "runtimeStatus": "Completed",
  "input": null,
  "customStatus": null,
  "output": [
    "Hello Seattle",
    "An error was thrown!",
    "Hello London"
  ],
  "createdTime": "2024-05-02T08:27:51Z",
  "lastUpdatedTime": "2024-05-02T08:27:52Z"
}

However, the Activity still fails. The log shows System.Private.CoreLib: Exception while executing function: Functions.hello. System.Private.CoreLib: Result: Failure.

In Python, it is idiomatic to return errors as exceptions and let them be handled by the calling function. This means that the Activity should not fail when an exception is raised, but rather when it is not handled by the calling Orchestrator, or a higher function.

The status does reflect that correctly with the runtime status of Completed. but the logs paint a different picture and make it seem like there was an unhandled issue in the code - which is not true. Thus, the raised Exception inside the Activity should not be printed to the output at all.

Then of course, there's the issue that the ValueError is raised as an Exception for some reason.