Skip to content

Commit

Permalink
CSharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
Theauxm committed Oct 14, 2024
1 parent 6cbe92f commit f1a0ac3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
19 changes: 8 additions & 11 deletions ChainSharp.Tests.Integration/IntegrationTests/WorkflowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public async Task TestChainWithShortCircuitStaysLeft()
workflow.Memory.Should().NotBeNull();
result.Should().NotBeNull();
}

[Theory]
public async Task TestWithException()
{
Expand All @@ -331,11 +331,11 @@ public async Task TestWithException()

Assert.ThrowsAsync<WorkflowException>(async () => await workflow.Run(Unit.Default));
}

private class ThrowsStep : Step<Unit, Unit>
{
public override Task<Unit> Run(Unit input)
=> throw new WorkflowException("This is a workflow exception.");
public override Task<Unit> Run(Unit input) =>
throw new WorkflowException("This is a workflow exception.");
}

private class OuterProperty
Expand Down Expand Up @@ -635,13 +635,10 @@ Ingredients input
.Resolve();
}
}

private class ChainTestWithException
: Workflow<Unit, Unit>

private class ChainTestWithException : Workflow<Unit, Unit>
{
protected override async Task<Either<Exception, Unit>> RunInternal(Unit input)
=> Activate(input)
.Chain<ThrowsStep>()
.Resolve();
protected override async Task<Either<Exception, Unit>> RunInternal(Unit input) =>
Activate(input).Chain<ThrowsStep>().Resolve();
}
}
14 changes: 10 additions & 4 deletions ChainSharp/Step/Step.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ public async Task<Either<Exception, TOut>> RailwayStep(Either<Exception, TIn> pr
}
catch (Exception e)
{
var messageField = typeof(Exception).GetField("_message", BindingFlags.Instance | BindingFlags.NonPublic);

var messageField = typeof(Exception).GetField(
"_message",
BindingFlags.Instance | BindingFlags.NonPublic
);

if (messageField != null)
messageField.SetValue(e, $"{{ \"Step\": \"{GetType().Name}\", \"Type\": \"{e.GetType().Name}\", \"Message\": \"{e.Message}\" }}");

messageField.SetValue(
e,
$"{{ \"Step\": \"{GetType().Name}\", \"Type\": \"{e.GetType().Name}\", \"Message\": \"{e.Message}\" }}"
);

Console.WriteLine($"Step: ({GetType().Name}) failed with Exception: ({e.Message})");
return e;
}
Expand Down

0 comments on commit f1a0ac3

Please sign in to comment.