diff --git a/test/e2e/Apps/BasicNode/package-lock.json b/test/e2e/Apps/BasicNode/package-lock.json index cce85f318..84ad66b8f 100644 --- a/test/e2e/Apps/BasicNode/package-lock.json +++ b/test/e2e/Apps/BasicNode/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "dependencies": { "@azure/functions": "^4.16.2", - "durable-functions": "^3.4.0" + "durable-functions": "^3.6.0" }, "devDependencies": { "@types/node": "^20.x", @@ -294,9 +294,9 @@ } }, "node_modules/durable-functions": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/durable-functions/-/durable-functions-3.4.0.tgz", - "integrity": "sha512-Wwgvcz/ccA7cIDo3lnbYusrys1KHJ+UII5RuMxk7lVejcG22HZR4L5EWidWaEKDayjLIvMg7W+u4S3EpdewJUg==", + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/durable-functions/-/durable-functions-3.6.0.tgz", + "integrity": "sha512-yY17ResBYV4CtsNvF4BpIQ4+SgFrXjecaHEWwwzjRuoFvRdqKWK9xI8Mz5Ed+De8nMNVesZ1jFCp390oqxqCzQ==", "license": "MIT", "dependencies": { "@azure/functions": "^4.14.0", diff --git a/test/e2e/Apps/BasicNode/package.json b/test/e2e/Apps/BasicNode/package.json index a933fe317..bc74b460c 100644 --- a/test/e2e/Apps/BasicNode/package.json +++ b/test/e2e/Apps/BasicNode/package.json @@ -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", diff --git a/test/e2e/Apps/BasicNode/src/Shared/ExceptionTypes.ts b/test/e2e/Apps/BasicNode/src/Shared/ExceptionTypes.ts index 188fe0339..ffa6bdf26 100644 --- a/test/e2e/Apps/BasicNode/src/Shared/ExceptionTypes.ts +++ b/test/e2e/Apps/BasicNode/src/Shared/ExceptionTypes.ts @@ -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; + listProperty: unknown[]; + nullProperty: unknown; + + constructor( + message: string, + stringProperty: string, + intProperty: number, + longProperty: number, + dateTimeProperty: string, + dictionaryProperty: Record, + 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; + } +} diff --git a/test/e2e/Apps/BasicNode/src/functions/CustomExceptionProperties.ts b/test/e2e/Apps/BasicNode/src/functions/CustomExceptionProperties.ts new file mode 100644 index 000000000..8e31cc153 --- /dev/null +++ b/test/e2e/Apps/BasicNode/src/functions/CustomExceptionProperties.ts @@ -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 | 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); diff --git a/test/e2e/Tests/Tests/ErrorHandlingTests.cs b/test/e2e/Tests/Tests/ErrorHandlingTests.cs index 4fbb074af..b920120e6 100644 --- a/test/e2e/Tests/Tests/ErrorHandlingTests.cs +++ b/test/e2e/Tests/Tests/ErrorHandlingTests.cs @@ -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; @@ -224,9 +225,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"); @@ -248,7 +247,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(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>(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>(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"]); @@ -288,4 +339,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); + + var orchestrationDetails = await DurableHelpers.GetRunningOrchestrationDetailsAsync(statusQueryGetUri); + // Deserialize the output (the sub-orchestration's FailureDetails) returned by the parent. + var failureDetails = JsonConvert.DeserializeObject(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); + } }