Azure / Azure/LogicAppsUX

Logic app Standard - Unit Testing exception when terminate with custom error code

Open
#9,270 0 comments 0 reactions 1 assignee Claimed by @andrew-eldridge View on GitHub
VSCode
Dominant language
TypeScript
Stars
111
Forks
109
Avg merge
1d 23h
Merged PRs (30d)
20

Description

### Severity

P3 - Medium (Minor functionality affected)

### Describe the Bug with repro steps

# Unit-testing SDK throws on workflows that Terminate with a custom (non-enum) error code

## Summary

`UnitTestExecutor.RunWorkflowAsync` throws `System.ArgumentException: Requested value '' was not found.` instead of returning a `Failed` `TestWorkflowRun` whenever the workflow run ends with a `runError.code` (or an action error `code`) that is not a member of the `ErrorResponseCode` enum.

Custom `Terminate` error codes are valid at runtime in Logic Apps Standard (the code field is a free-form string), so this makes it impossible to unit-test any error/Catch path that terminates with a domain-specific code.

## Repro

1. Author a Stateful workflow with a Try/Catch pattern whose Catch terminates the run:

```json
"Terminate_-_Failed": {
"type": "Terminate",
"inputs": {
"runStatus": "Failed",
"runError": {
"code": "@variables('ErrorCode')",
"message": "@variables('ErrorMessage')"
}
}
}

where `ErrorCode` resolves to a custom string, e.g. `"PublisherDeliveryFailed_APICallFailed"`.

2. Mock the actions so the run reaches `Terminate_-_Failed`, then:

```csharp
var run = await executor.Create().RunWorkflowAsync(testMock: mockData);
```

### What type of Logic App Is this happening in?

Standard (VSCode)

### Are you experiencing a regression?

_No response_

### Which operating system are you using?

Windows

### Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

### Workflow JSON

```json

```

### Screenshots or Videos

_No response_

### Environment

- Package: `Microsoft.Azure.Workflows.WebJobs.Tests.Extension` **1.0.3** (latest on NuGet)
- Target framework: `net8.0`
- Test framework: MSTest

### Additional context

```log
Requested value 'PublisherDeliveryFailed_APICallFailed' was not found.
at Microsoft.Azure.Workflows.UnitTesting.TestHost.UnitTestEngine.ExecuteWorkflow(FlowPropertiesDefinition workflowDefinition, TriggerMock triggerMock, Dictionary`2 actionMocks, String appDirectory, String connections, String parameters, IDictionary`2 localSettings, String customCodeFunctionFilePath, Int32 timeoutInSeconds)
at Microsoft.Azure.Workflows.UnitTesting.TestHost.UnitTestEngine.ExecuteWorkflow(FlowPropertiesDefinition workflowDefinition, TriggerMock triggerMock, Dictionary`2 actionMocks, String appDirectory, String connections, String parameters, IDictionary`2 localSettings, String customCodeFunctionFilePath, Int32 timeoutInSeconds)
at Microsoft.Azure.Workflows.UnitTesting.UnitTestExecutor.RunWorkflowAsync(TestMockDefinition testMock, Int32 timeoutInSeconds)
at Integration.Erp04.LogicApps.Tests.Failed_Run.RunAndCaptureAsync(String mockName) in C:\Repo\CHC.Integration.ERP\tests\erp04\Integration.Erp04.LogicApps\int22svc01p01-residentmovements-ecase-pub\Failed-Run\Failed-Run.cs:line 100

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.