Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
8 changes: 4 additions & 4 deletions test/e2e/Apps/BasicNode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/e2e/Apps/BasicNode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@azure/functions": "^4.16.2",
"durable-functions": "^3.4.0"
"durable-functions": "^3.6.0"
},
"devDependencies": {
"@types/node": "^20.x",
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);
1 change: 1 addition & 0 deletions test/e2e/Tests/Localizers/NodeTestLanguageLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ internal class NodeTestLanguageLocalizer : ITestLanguageLocalizer
private readonly Dictionary<string, string> nodeLocalizedStrings = new Dictionary<string, string>
{
{ "CaughtActivityException.ErrorMessage", "Caught exception: Error: Activity function 'raise_exception' failed:" },
{ "CaughtActivityException.MSSQLErrorMessage", "Caught exception: Error: Activity function 'raise_exception' failed:" },
{ "RethrownActivityException.ErrorMessage", "Orchestrator function 'RethrowActivityException' failed: Activity function 'raise_exception' failed: " },
// Bug: https://github.com/Azure/azure-functions-durable-js/issues/642
{ "CaughtEntityException.ErrorMessage", "Error: [object Object]" },
Expand Down
123 changes: 119 additions & 4 deletions test/e2e/Tests/Tests/ErrorHandlingTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Globalization;
using System.Net;
using Microsoft.DurableTask;
using Newtonsoft.Json;
Expand Down Expand Up @@ -79,7 +80,12 @@ public async Task OrchestratorWithCaughtActivityException_ShouldSucceed()
await DurableHelpers.WaitForOrchestrationStateAsync(statusQueryGetUri, "Completed", 30);

var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri);
Assert.StartsWith(this.fixture.functionLanguageLocalizer?.GetLocalizedStringValue("CaughtActivityException.ErrorMessage"), orchestrationDetails.Output);
bool isNodeMSSQL = this.fixture.functionLanguageLocalizer.GetLanguageType() == LanguageType.Node
&& this.fixture.GetDurabilityProvider() == FunctionAppFixture.ConfiguredDurabilityProviderType.MSSQL;
string errorMessageKey = isNodeMSSQL
? "CaughtActivityException.MSSQLErrorMessage"
: "CaughtActivityException.ErrorMessage";
Assert.StartsWith(this.fixture.functionLanguageLocalizer.GetLocalizedStringValue(errorMessageKey), orchestrationDetails.Output);
Assert.Contains("This activity failed", orchestrationDetails.Output);
}

Expand Down Expand Up @@ -224,9 +230,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 +252,59 @@ 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.TryGetValue("StringProperty", out var stringPropertyValue));
Assert.Equal("validation-error-123", stringPropertyValue);

// Verify numeric properties (JSON numbers => double)
Assert.True(failureDetails.Properties.TryGetValue("IntProperty", out var intPropertyValue));
Assert.Equal(100L, Convert.ToInt64(intPropertyValue));

Assert.True(failureDetails.Properties.TryGetValue("LongProperty", out var longPropertyValue));
Assert.Equal(999999999L, Convert.ToInt64(longPropertyValue));

// Verify DateTime property (sent as ISO-8601 string by the JS SDK)
Assert.True(failureDetails.Properties.TryGetValue("DateTimeProperty", out var dateTimePropertyValue));
var dateTimeProperty = dateTimePropertyValue is DateTime dateTime
? dateTime
: DateTime.Parse(Assert.IsType<string>(dateTimePropertyValue), CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
Assert.Equal(
new DateTime(2025, 10, 15, 14, 30, 0, DateTimeKind.Utc),
dateTimeProperty.ToUniversalTime());

// Verify dictionary property (nested object)
Assert.True(failureDetails.Properties.TryGetValue("DictionaryProperty", out var dictionaryPropertyValue));
var nodeDictProperty = JsonConvert.DeserializeObject<Dictionary<string, object>>(dictionaryPropertyValue!.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.TryGetValue("ListProperty", out var listPropertyValue));
var nodeListProperty = JsonConvert.DeserializeObject<List<object>>(listPropertyValue!.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.TryGetValue("NullProperty", out var nullPropertyValue));
Assert.Null(nullPropertyValue);

return;
}

// Verify string property
Assert.True(failureDetails.Properties.ContainsKey("StringProperty"));
Assert.Equal("validation-error-123", failureDetails.Properties["StringProperty"]);
Expand Down Expand Up @@ -288,4 +344,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.TryGetValue("StringProperty", out var stringPropertyValue));
Assert.Equal("validation-error-123", stringPropertyValue);

Assert.True(businessFailure.Properties.TryGetValue("IntProperty", out var intPropertyValue));
Assert.Equal(100L, Convert.ToInt64(intPropertyValue));

Assert.True(businessFailure.Properties.TryGetValue("LongProperty", out var longPropertyValue));
Assert.Equal(999999999L, Convert.ToInt64(longPropertyValue));

Assert.True(businessFailure.Properties.TryGetValue("NullProperty", out var nullPropertyValue));
Assert.Null(nullPropertyValue);
}
}
Loading