Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/e2e/Apps/BasicNode/extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.3" />
<PackageReference Include="Microsoft.DurableTask.SqlServer.AzureFunctions" Version="1.5.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask.AzureManaged" Version="0.4.2-alpha" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask.AzureManaged" Version="1.9.0" />
Comment thread
nytian marked this conversation as resolved.
Resolved

<ProjectReference Include="..\..\..\..\src\WebJobs.Extensions.DurableTask\WebJobs.Extensions.DurableTask.csproj" />
</ItemGroup>
Expand Down
38 changes: 38 additions & 0 deletions test/e2e/Apps/BasicNode/src/Shared/ExceptionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,41 @@ export class OverflowException extends ErrorWithCause {
this.name = "OverflowException";
}
}

// Custom exception carrying structured properties, mirroring the .NET isolated
// BusinessValidationException used by CustomExceptionPropertiesInFailureDetails.
// Extends Error directly (not ErrorWithCause) so `message` stays the plain
// exception message ("Business logic validation failed"), matching the .NET
// reference where FailureDetails.ErrorMessage has no type prefix.
export class BusinessValidationException extends Error {
stringProperty: string;
intProperty: number;
longProperty: number;
dateTimeProperty: string;
dictionaryProperty: Record<string, unknown>;
listProperty: unknown[];
nullProperty: unknown;

constructor(
message: string,
stringProperty: string,
intProperty: number,
longProperty: number,
dateTimeProperty: string,
dictionaryProperty: Record<string, unknown>,
listProperty: unknown[],
nullProperty: unknown
) {
super(message);
this.name = "BusinessValidationException";
// Fix the prototype chain (necessary when extending built-ins in TypeScript)
Object.setPrototypeOf(this, new.target.prototype);
this.stringProperty = stringProperty;
this.intProperty = intProperty;
this.longProperty = longProperty;
this.dateTimeProperty = dateTimeProperty;
this.dictionaryProperty = dictionaryProperty;
this.listProperty = listProperty;
this.nullProperty = nullProperty;
}
}
101 changes: 101 additions & 0 deletions test/e2e/Apps/BasicNode/src/functions/CustomExceptionProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import * as df from 'durable-functions';
import {
ActivityHandler,
ExceptionPropertiesProvider,
OrchestrationContext,
OrchestrationHandler,
TaskFailedError,
} from 'durable-functions';
import { BusinessValidationException } from '../Shared/ExceptionTypes';

// Register a global provider that surfaces custom properties from thrown
// exceptions into FailureDetails.Properties. Mirrors the .NET isolated
// TestExceptionPropertiesProvider used by BasicDotNetIsolated.
const provider: ExceptionPropertiesProvider = {
getExceptionProperties(error: unknown): Record<string, unknown> | undefined {
if (error instanceof BusinessValidationException) {
return {
StringProperty: error.stringProperty,
IntProperty: error.intProperty,
LongProperty: error.longProperty,
DateTimeProperty: error.dateTimeProperty,
DictionaryProperty: error.dictionaryProperty,
ListProperty: error.listProperty,
NullProperty: error.nullProperty,
};
}
return undefined;
},
};
df.app.setExceptionPropertiesProvider(provider);

// Activity: BusinessActivity - throws an exception carrying custom properties.
const BusinessActivity: ActivityHandler = (): void => {
throw new BusinessValidationException(
"Business logic validation failed",
"validation-error-123",
100,
999999999,
"2025-10-15T14:30:00.000Z",
{
error_code: "VALIDATION_FAILED",
retry_count: 3,
is_critical: true,
},
["error1", "error2", 500, null],
null
);
};
df.app.activity("BusinessActivity", { handler: BusinessActivity });

// Sub-orchestration: calls the activity and lets the failure (with its
// structured FailureDetails) propagate out so a parent can observe it. Used by
// the nested scenario below.
const BusinessSubOrchestration: OrchestrationHandler = function* (context: OrchestrationContext) {
yield context.df.callActivity("BusinessActivity");
};
df.app.orchestration("BusinessSubOrchestration", BusinessSubOrchestration);

// Parent orchestration: calls the activity directly, catches the propagated
// TaskFailedError, and returns its FailureDetails. This mirrors the .NET
// isolated OrchestrationWithCustomException reference so the custom-exception-
// properties feature is validated for Node exactly as it works for dotnet
// isolated.
const OrchestrationWithCustomException: OrchestrationHandler = function* (context: OrchestrationContext) {
try {
yield context.df.callActivity("BusinessActivity");
} catch (e: unknown) {
if (e instanceof TaskFailedError) {
return e.failureDetails;
}
throw e;
}

// Should never reach here.
return null;
};
df.app.orchestration("OrchestrationWithCustomException", OrchestrationWithCustomException);

// Nested scenario: parent orchestration that calls a sub-orchestration (which
// in turn calls the failing activity), catches the propagated TaskFailedError,
// and returns its FailureDetails — exercising FailureDetails propagation across
// a sub-orchestration boundary.
const NestedOrchestrationWithCustomException: OrchestrationHandler = function* (
context: OrchestrationContext
) {
try {
yield context.df.callSubOrchestrator("BusinessSubOrchestration");
} catch (e: unknown) {
if (e instanceof TaskFailedError) {
return e.failureDetails;
}
throw e;
}

// Should never reach here.
return null;
};
df.app.orchestration("NestedOrchestrationWithCustomException", NestedOrchestrationWithCustomException);
112 changes: 109 additions & 3 deletions test/e2e/Tests/Tests/ErrorHandlingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ await this.fixture.TestLogs.AssertLogExistsAsync(
[Fact]
[Trait("PowerShell", "Skip")] // FailureDetails is a dotnet-isolated implementation detail
[Trait("Python", "Skip")] // FailureDetails is a dotnet-isolated implementation detail
[Trait("Node", "Skip")] // Custom exception properties are not yet supported by the durable-functions JS SDK.
[Trait("Java", "Skip")] // Include exception properties at Failure Details for Java is not supported yet.
[Trait("DTS", "Skip")] // DTS doesn't support this feature yet.
public async Task CustomExceptionPropertiesInFailureDetails()
{
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("StartOrchestration", "?orchestrationName=OrchestrationWithCustomException");
Expand All @@ -248,7 +246,56 @@ public async Task CustomExceptionPropertiesInFailureDetails()

// Check that custom properties are included
Assert.NotNull(failureDetails.Properties);


if (this.fixture.functionLanguageLocalizer.GetLanguageType() == LanguageType.Node)
{
// The durable-functions JS SDK serializes custom exception properties to JSON
// and the host parses them as protobuf Values. JSON has no distinct int/long type
// (numbers round-trip as doubles) and no native DateTime (sent as an ISO-8601 string),
// so the expected .NET types differ from the dotnet-isolated worker.

// Verify string property
Assert.True(failureDetails.Properties.ContainsKey("StringProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal("validation-error-123", failureDetails.Properties["StringProperty"]);

// Verify numeric properties (JSON numbers => double)
Assert.True(failureDetails.Properties.ContainsKey("IntProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal(100L, Convert.ToInt64(failureDetails.Properties["IntProperty"]));

Assert.True(failureDetails.Properties.ContainsKey("LongProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal(999999999L, Convert.ToInt64(failureDetails.Properties["LongProperty"]));

// Verify DateTime property (sent as ISO-8601 string by the JS SDK)
Assert.True(failureDetails.Properties.ContainsKey("DateTimeProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal(
new DateTime(2025, 10, 15, 14, 30, 0, DateTimeKind.Utc),
Convert.ToDateTime(failureDetails.Properties["DateTimeProperty"]).ToUniversalTime());
Comment thread
nytian marked this conversation as resolved.
Resolved
Comment thread
nytian marked this conversation as resolved.
Resolved

// Verify dictionary property (nested object)
Assert.True(failureDetails.Properties.ContainsKey("DictionaryProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
var nodeDictProperty = JsonConvert.DeserializeObject<Dictionary<string, object>>(failureDetails.Properties["DictionaryProperty"]!.ToString()!);
Assert.NotNull(nodeDictProperty);
Assert.Equal("VALIDATION_FAILED", nodeDictProperty["error_code"]);
Assert.Equal(3L, Convert.ToInt64(nodeDictProperty["retry_count"]));
Assert.Equal(true, nodeDictProperty["is_critical"]);

// Verify list property
Assert.True(failureDetails.Properties.ContainsKey("ListProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
var nodeListProperty = JsonConvert.DeserializeObject<List<object>>(failureDetails.Properties["ListProperty"]!.ToString()!);
Assert.NotNull(nodeListProperty);
Assert.Equal(4, nodeListProperty.Count);
Assert.Equal("error1", nodeListProperty[0]);
Assert.Equal("error2", nodeListProperty[1]);
Assert.Equal(500L, Convert.ToInt64(nodeListProperty[2]));
Assert.Null(nodeListProperty[3]);

// Verify null property
Assert.True(failureDetails.Properties.ContainsKey("NullProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Null(failureDetails.Properties["NullProperty"]);

return;
}

// Verify string property
Assert.True(failureDetails.Properties.ContainsKey("StringProperty"));
Assert.Equal("validation-error-123", failureDetails.Properties["StringProperty"]);
Expand Down Expand Up @@ -288,4 +335,63 @@ public async Task CustomExceptionPropertiesInFailureDetails()
Assert.True(failureDetails.Properties.ContainsKey("NullProperty"));
Assert.Null(failureDetails.Properties["NullProperty"]);
}

[Fact]
[Trait("Dotnet", "Skip")] // NestedOrchestrationWithCustomException is only registered in the BasicNode app.
[Trait("PowerShell", "Skip")] // FailureDetails is a dotnet-isolated implementation detail
[Trait("Python", "Skip")] // FailureDetails is a dotnet-isolated implementation detail
[Trait("Java", "Skip")] // Include exception properties at Failure Details for Java is not supported yet.
public async Task NestedCustomExceptionPropertiesInFailureDetails()
{
// A parent orchestration calls a sub-orchestration, which calls the failing
// activity. The activity's custom exception properties must survive being
// nested inside the sub-orchestration's FailureDetails.InnerFailure chain so
// the parent can still observe them.
using HttpResponseMessage response = await HttpHelpers.InvokeHttpTrigger("StartOrchestration", "?orchestrationName=NestedOrchestrationWithCustomException");

Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);

string statusQueryGetUri = await DurableHelpers.ParseStatusQueryGetUriAsync(response);

await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Completed", 30);
Comment thread
sophiatev marked this conversation as resolved.
Resolved

var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri);
// Deserialize the output (the sub-orchestration's FailureDetails) returned by the parent.
var failureDetails = JsonConvert.DeserializeObject<TaskFailureDetails>(orchestrationDetails.Output);
Assert.NotNull(failureDetails);

// Walk the InnerFailure chain to find the original activity exception that
// carries the custom properties.
static TaskFailureDetails? FindFailureByErrorType(TaskFailureDetails? details, string errorTypeSubstring)
{
for (TaskFailureDetails? current = details; current != null; current = current.InnerFailure)
{
if (current.ErrorType != null && current.ErrorType.Contains(errorTypeSubstring))
{
return current;
}
}

return null;
}

var businessFailure = FindFailureByErrorType(failureDetails, "BusinessValidationException");
Assert.NotNull(businessFailure);
Assert.Equal("Business logic validation failed", businessFailure!.ErrorMessage);

// The custom properties must be preserved on the nested activity failure.
Assert.NotNull(businessFailure.Properties);

Assert.True(businessFailure.Properties.ContainsKey("StringProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal("validation-error-123", businessFailure.Properties["StringProperty"]);

Assert.True(businessFailure.Properties.ContainsKey("IntProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal(100L, Convert.ToInt64(businessFailure.Properties["IntProperty"]));

Assert.True(businessFailure.Properties.ContainsKey("LongProperty"));
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed
Assert.Equal(999999999L, Convert.ToInt64(businessFailure.Properties["LongProperty"]));

Assert.True(businessFailure.Properties.ContainsKey("NullProperty"));
Assert.Null(businessFailure.Properties["NullProperty"]);
}
}
Loading