Skip to content

Commit 431dbac

Browse files
committed
update by comments
1 parent a0af07c commit 431dbac

10 files changed

+86
-83
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// ----------------------------------------------------------------------------------
2+
// Copyright Microsoft Corporation
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
// ----------------------------------------------------------------------------------
13+
#nullable enable
14+
namespace DurableTask.Core
15+
{
16+
using System;
17+
using System.Collections.Generic;
18+
using DurableTask.Core.Exceptions;
19+
20+
/// <summary>
21+
/// Extension methods for <see cref="IExceptionPropertiesProvider"/>.
22+
/// </summary>
23+
internal static class ExceptionPropertiesProviderExtensions
24+
{
25+
/// <summary>
26+
/// Extracts properties for the specified rules with the provider.
27+
/// </summary>
28+
public static IDictionary<string, object>? ExtractProperties(this IExceptionPropertiesProvider? provider, Exception exception)
29+
{
30+
if (exception is OrchestrationException orchestrationException &&
31+
orchestrationException.FailureDetails?.Properties != null)
32+
{
33+
return orchestrationException.FailureDetails.Properties;
34+
}
35+
36+
if (provider == null)
37+
{
38+
return null;
39+
}
40+
41+
return provider.GetExceptionProperties(exception);
42+
}
43+
}
44+
}
45+
46+

src/DurableTask.Core/FailureDetails.cs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,29 @@ public class FailureDetails : IEquatable<FailureDetails>
3838
/// <param name="stackTrace">The exception stack trace.</param>
3939
/// <param name="innerFailure">The inner cause of the failure.</param>
4040
/// <param name="isNonRetriable">Whether the failure is non-retriable.</param>
41+
/// <param name="properties">Additional properties associated with the failure.</param>
4142
[JsonConstructor]
42-
public FailureDetails(string errorType, string errorMessage, string? stackTrace, FailureDetails? innerFailure, bool isNonRetriable)
43+
public FailureDetails(string errorType, string errorMessage, string? stackTrace, FailureDetails? innerFailure, bool isNonRetriable, IDictionary<string, object>? properties = null)
4344
{
4445
this.ErrorType = errorType;
4546
this.ErrorMessage = errorMessage;
4647
this.StackTrace = stackTrace;
4748
this.InnerFailure = innerFailure;
4849
this.IsNonRetriable = isNonRetriable;
50+
this.Properties = properties;
51+
}
52+
53+
/// <summary>
54+
/// Initializes a new instance of the <see cref="FailureDetails"/> class.
55+
/// </summary>
56+
/// <param name="errorType">The name of the error, which is expected to the the namespace-qualified name of the exception type.</param>
57+
/// <param name="errorMessage">The message associated with the error, which is expected to be the exception's <see cref="Exception.Message"/> property.</param>
58+
/// <param name="stackTrace">The exception stack trace.</param>
59+
/// <param name="innerFailure">The inner cause of the failure.</param>
60+
/// <param name="isNonRetriable">Whether the failure is non-retriable.</param>
61+
public FailureDetails(string errorType, string errorMessage, string? stackTrace, FailureDetails? innerFailure, bool isNonRetriable)
62+
: this(errorType, errorMessage, stackTrace, innerFailure, isNonRetriable, properties:null)
63+
{
4964
}
5065

5166
/// <summary>
@@ -54,7 +69,7 @@ public FailureDetails(string errorType, string errorMessage, string? stackTrace,
5469
/// <param name="e">The exception used to generate the failure details.</param>
5570
/// <param name="innerFailure">The inner cause of the failure.</param>
5671
public FailureDetails(Exception e, FailureDetails innerFailure)
57-
: this(e, innerFailure, null)
72+
: this(e, innerFailure, properties: null)
5873
{
5974
}
6075

@@ -63,31 +78,29 @@ public FailureDetails(Exception e, FailureDetails innerFailure)
6378
/// </summary>
6479
/// <param name="e">The exception used to generate the failure details.</param>
6580
public FailureDetails(Exception e)
66-
: this(e, (IExceptionPropertiesProvider?)null)
81+
: this(e, properties: null)
6782
{
6883
}
6984

7085
/// <summary>
7186
/// Initializes a new instance of the <see cref="FailureDetails"/> class from an exception object.
7287
/// </summary>
7388
/// <param name="e">The exception used to generate the failure details.</param>
74-
/// <param name="exceptionPropertiesProvider">The provider to extract custom properties from the exception.</param>
75-
public FailureDetails(Exception e, IExceptionPropertiesProvider? exceptionPropertiesProvider)
76-
: this(e.GetType().FullName, GetErrorMessage(e), e.StackTrace, FromException(e.InnerException, exceptionPropertiesProvider), false)
89+
/// <param name="properties">The exception properties to include in failure details.</param>
90+
public FailureDetails(Exception e, IDictionary<string, object>? properties)
91+
: this(e.GetType().FullName, GetErrorMessage(e), e.StackTrace, FromException(e.InnerException), false, properties)
7792
{
78-
this.Properties = GetExceptionProperties(e, exceptionPropertiesProvider);
7993
}
8094

8195
/// <summary>
8296
/// Initializes a new instance of the <see cref="FailureDetails"/> class from an exception object.
8397
/// </summary>
8498
/// <param name="e">The exception used to generate the failure details.</param>
8599
/// <param name="innerFailure">The inner cause of the failure.</param>
86-
/// <param name="exceptionPropertiesProvider">The provider to extract custom properties from the exception.</param>
87-
public FailureDetails(Exception e, FailureDetails innerFailure, IExceptionPropertiesProvider? exceptionPropertiesProvider)
88-
: this(e.GetType().FullName, GetErrorMessage(e), e.StackTrace, innerFailure, false)
100+
/// <param name="properties">The exception properties to include in failure details.</param>
101+
public FailureDetails(Exception e, FailureDetails innerFailure, IDictionary<string, object>? properties)
102+
: this(e.GetType().FullName, GetErrorMessage(e), e.StackTrace, innerFailure, false, properties)
89103
{
90-
this.Properties = GetExceptionProperties(e, exceptionPropertiesProvider);
91104
}
92105

93106
/// <summary>
@@ -243,31 +256,12 @@ static string GetErrorMessage(Exception e)
243256

244257
static FailureDetails? FromException(Exception? e)
245258
{
246-
return FromException(e, null);
247-
}
248-
249-
static FailureDetails? FromException(Exception? e, IExceptionPropertiesProvider? provider)
250-
{
251-
return e == null ? null : new FailureDetails(e, provider);
259+
return FromException(e, properties : null);
252260
}
253261

254-
static IDictionary<string, object>? GetExceptionProperties(Exception exception, IExceptionPropertiesProvider? provider)
262+
static FailureDetails? FromException(Exception? e, IDictionary<string, object>? properties)
255263
{
256-
// If this is a TaskFailedException that already has FailureDetails with properties,
257-
// use those properties instead of asking the provider
258-
if (exception is OrchestrationException orchestrationException &&
259-
orchestrationException.FailureDetails?.Properties != null)
260-
{
261-
return orchestrationException.FailureDetails.Properties;
262-
}
263-
264-
if (provider == null)
265-
{
266-
return null;
267-
}
268-
269-
// If there is a provider provided, then extract exception properties with the provider.
270-
return provider.GetExceptionProperties(exception);
264+
return e == null ? null : new FailureDetails(e, properties : properties);
271265
}
272266

273267
}

src/DurableTask.Core/ReflectionBasedTaskActivity.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ public override async Task<string> RunAsync(TaskContext context, string input)
140140
}
141141
else
142142
{
143-
failureDetails = new FailureDetails(exception, context.ExceptionPropertiesProvider);
143+
var props = context.ExceptionPropertiesProvider.ExtractProperties(exception);
144+
failureDetails = new FailureDetails(exception, props);
144145
}
145146

146147
throw new TaskFailureException(exception.Message, exception, details)

src/DurableTask.Core/TaskActivity.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
namespace DurableTask.Core
1515
{
16-
using System;
17-
using System.Threading.Tasks;
1816
using DurableTask.Core.Common;
1917
using DurableTask.Core.Exceptions;
2018
using DurableTask.Core.Serializing;
2119
using Newtonsoft.Json.Linq;
20+
using System;
21+
using System.Threading.Tasks;
2222

2323
/// <summary>
2424
/// Base class for TaskActivity.
@@ -144,7 +144,8 @@ public override async Task<string> RunAsync(TaskContext context, string input)
144144
{
145145
if(context != null)
146146
{
147-
failureDetails = new FailureDetails(e, context.ExceptionPropertiesProvider);
147+
var props = context.ExceptionPropertiesProvider.ExtractProperties(e);
148+
failureDetails = new FailureDetails(e, props);
148149
}
149150
else
150151
{

src/DurableTask.Core/TaskActivityDispatcher.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ public sealed class TaskActivityDispatcher
3838
readonly ErrorPropagationMode errorPropagationMode;
3939
readonly IExceptionPropertiesProvider? exceptionPropertiesProvider;
4040

41-
internal TaskActivityDispatcher(
42-
IOrchestrationService orchestrationService,
43-
INameVersionObjectManager<TaskActivity> objectManager,
44-
DispatchMiddlewarePipeline dispatchPipeline,
45-
LogHelper logHelper,
46-
ErrorPropagationMode errorPropagationMode)
47-
: this(orchestrationService, objectManager, dispatchPipeline, logHelper, errorPropagationMode, null)
48-
{
49-
}
50-
5141
/// <summary>
5242
/// Initializes a new instance of the <see cref="TaskActivityDispatcher"/> class with an exception properties provider.
5343
/// </summary>
@@ -230,7 +220,7 @@ await this.dispatchPipeline.RunAsync(dispatchContext, async _ =>
230220
string? details = this.IncludeDetails
231221
? $"Unhandled exception while executing task: {e}"
232222
: null;
233-
responseEvent = new TaskFailedEvent(-1, scheduledEvent.EventId, e.Message, details, new FailureDetails(e, this.exceptionPropertiesProvider));
223+
responseEvent = new TaskFailedEvent(-1, scheduledEvent.EventId, e.Message, details, new FailureDetails(e));
234224

235225
traceActivity?.SetStatus(ActivityStatusCode.Error, e.Message);
236226

src/DurableTask.Core/TaskEntityDispatcher.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ public class TaskEntityDispatcher
4444
readonly TaskOrchestrationDispatcher.NonBlockingCountdownLock concurrentSessionLock;
4545
readonly IExceptionPropertiesProvider exceptionPropertiesProvider;
4646

47-
internal TaskEntityDispatcher(
48-
IOrchestrationService orchestrationService,
49-
INameVersionObjectManager<TaskEntity> entityObjectManager,
50-
DispatchMiddlewarePipeline entityDispatchPipeline,
51-
LogHelper logHelper,
52-
ErrorPropagationMode errorPropagationMode)
53-
: this(orchestrationService, entityObjectManager, entityDispatchPipeline, logHelper, errorPropagationMode, null)
54-
{
55-
}
56-
5747
/// <summary>
5848
/// Initializes a new instance of the <see cref="TaskEntityDispatcher"/> class with an exception properties provider.
5949
/// </summary>

src/DurableTask.Core/TaskOrchestration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public override async Task<string> Execute(OrchestrationContext context, string
105105
}
106106
else
107107
{
108-
failureDetails = new FailureDetails(e, context.ExceptionPropertiesProvider);
108+
var props = context.ExceptionPropertiesProvider.ExtractProperties(e);
109+
failureDetails = new FailureDetails(e, props);
109110
}
110111

111112
throw new OrchestrationFailureException(e.Message, details)

src/DurableTask.Core/TaskOrchestrationContext.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,8 @@ public TaskOrchestrationContext(
5252
OrchestrationInstance orchestrationInstance,
5353
TaskScheduler taskScheduler,
5454
TaskOrchestrationEntityParameters entityParameters = null,
55-
ErrorPropagationMode errorPropagationMode = ErrorPropagationMode.SerializeExceptions)
56-
: this(orchestrationInstance, taskScheduler, entityParameters, errorPropagationMode, null)
57-
{
58-
}
59-
60-
public TaskOrchestrationContext(
61-
OrchestrationInstance orchestrationInstance,
62-
TaskScheduler taskScheduler,
63-
TaskOrchestrationEntityParameters entityParameters,
64-
ErrorPropagationMode errorPropagationMode,
65-
IExceptionPropertiesProvider exceptionPropertiesProvider)
55+
ErrorPropagationMode errorPropagationMode = ErrorPropagationMode.SerializeExceptions,
56+
IExceptionPropertiesProvider exceptionPropertiesProvider = null)
6657
{
6758
Utils.UnusedParameter(taskScheduler);
6859

@@ -696,7 +687,7 @@ public void FailOrchestration(Exception failure, OrchestrationRuntimeState runti
696687
{
697688
if (this.ErrorPropagationMode == ErrorPropagationMode.UseFailureDetails)
698689
{
699-
failureDetails = new FailureDetails(failure, this.exceptionPropertiesProvider);
690+
failureDetails = new FailureDetails(failure);
700691
}
701692
else
702693
{

src/DurableTask.Core/TaskOrchestrationDispatcher.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@ public class TaskOrchestrationDispatcher
5151
readonly VersioningSettings? versioningSettings;
5252
readonly IExceptionPropertiesProvider? exceptionPropertiesProvider;
5353

54-
internal TaskOrchestrationDispatcher(
55-
IOrchestrationService orchestrationService,
56-
INameVersionObjectManager<TaskOrchestration> objectManager,
57-
DispatchMiddlewarePipeline dispatchPipeline,
58-
LogHelper logHelper,
59-
ErrorPropagationMode errorPropagationMode,
60-
VersioningSettings versioningSettings)
61-
: this(orchestrationService, objectManager, dispatchPipeline, logHelper, errorPropagationMode, versioningSettings, null)
62-
{
63-
}
64-
6554
/// <summary>
6655
/// Initializes a new instance of the <see cref="TaskOrchestrationDispatcher"/> class with an exception properties provider.
6756
/// </summary>

test/DurableTask.Core.Tests/TestTaskEntityDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private TaskEntityDispatcher GetTaskEntityDispatcher()
3030
var logger = new LogHelper(loggerFactory?.CreateLogger("DurableTask.Core"));
3131

3232
TaskEntityDispatcher dispatcher = new TaskEntityDispatcher(
33-
service, entityManager, entityMiddleware, logger, ErrorPropagationMode.UseFailureDetails);
33+
service, entityManager, entityMiddleware, logger, ErrorPropagationMode.UseFailureDetails, null);
3434
return dispatcher;
3535
}
3636

0 commit comments

Comments
 (0)