Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion src/Dapr.Workflow/Client/ProtoConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static WorkflowMetadata ToWorkflowMetadata(Dapr.DurableTask.Protobuf.Work
{
SerializedInput = string.IsNullOrEmpty(state.Input) ? null : state.Input,
SerializedOutput = string.IsNullOrEmpty(state.Output) ? null : state.Output,
SerializedCustomStatus = string.IsNullOrEmpty(state.CustomStatus) ? null : state.CustomStatus
SerializedCustomStatus = string.IsNullOrEmpty(state.CustomStatus) ? null : state.CustomStatus,
FailureDetails = ToWorkflowTaskFailureDetails(state.FailureDetails),
};

/// <summary>
Expand Down Expand Up @@ -91,4 +92,12 @@ public static WorkflowHistoryEventType ToHistoryEventType(HistoryEvent.EventType
HistoryEvent.EventTypeOneofCase.DetachedWorkflowInstanceCreated => WorkflowHistoryEventType.SubOrchestrationInstanceCreated,
_ => WorkflowHistoryEventType.Unknown
};

private static Workflow.WorkflowTaskFailureDetails? ToWorkflowTaskFailureDetails(TaskFailureDetails? failureDetails)
=> failureDetails is null
? null
: new Workflow.WorkflowTaskFailureDetails(
failureDetails.ErrorType,
failureDetails.ErrorMessage,
string.IsNullOrEmpty(failureDetails.StackTrace) ? null : failureDetails.StackTrace);
}
26 changes: 26 additions & 0 deletions test/Dapr.Workflow.Test/Client/ProtoConvertersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ public void ToWorkflowMetadata_ShouldSetSerializedFieldsToNull_WhenProtoStringsA
Assert.Null(metadata.SerializedCustomStatus);
}

[Fact]
public void ToWorkflowMetadata_ShouldMapFailureDetails_WhenPresent()
{
var serializer = new JsonDaprSerializer();

var state = new Dapr.DurableTask.Protobuf.WorkflowState
{
InstanceId = "i",
Name = "n",
WorkflowStatus = OrchestrationStatus.Failed,
FailureDetails = new TaskFailureDetails
{
ErrorType = "System.InvalidOperationException",
ErrorMessage = "boom",
StackTrace = "trace"
}
};

var metadata = ProtoConverters.ToWorkflowMetadata(state, serializer);

Assert.NotNull(metadata.FailureDetails);
Assert.Equal("System.InvalidOperationException", metadata.FailureDetails!.ErrorType);
Assert.Equal("boom", metadata.FailureDetails.ErrorMessage);
Assert.Equal("trace", metadata.FailureDetails.StackTrace);
}

[Fact]
public void ToWorkflowMetadata_ShouldKeepSerializedFields_WhenProtoStringsContainWhitespace()
{
Expand Down
Loading