elsa-workflows / elsa-workflows/elsa-core

Display Faulted Activity in Journal

Open
#2,723 0 comments 0 reactions 0 assignees View on GitHub
enhancement triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

Hello @sfmskywalker,

To make custom activity to **Failed ** state in case of any business logic exception, I have implemented the following options in the custom activity exception block:

**Option1:** **throw(ex)** statement
```
try
{
//Business logic
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
throw (ex);
}
```

If I use the throw statement, I have observed that in the workflow execution instance with fault exception along with fault message and activity state also as "**Faulted**" and also Workflow status as "**Faulted**"
![image](https://user-images.githubusercontent.com/67507118/150673517-5662dde5-7420-44e4-9fba-afbc7a8ffad3.png)

![image](https://user-images.githubusercontent.com/67507118/150673659-4993b8b5-5e79-4b64-91c5-746ae0dab2bc.png)

**Option II: Return fault(ex)**
```
try
{
//Business logic
return Done();
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
return Fault(ex)
}
```

In this case I have observed in the Workflow execution instance as follow: Activity state is "**Executed**" and Workflow status as "**Faulted**"
![image](https://user-images.githubusercontent.com/67507118/150674104-7d4aef61-c2b2-43a9-a5d6-011416d2b881.png)"
![image](https://user-images.githubusercontent.com/67507118/150674118-766c4c56-da9e-46c4-b320-98fb76302c72.png)

**Option -III:** Implemented **WorkflowFault** method.
```
try
{
//Business logic
}
catch (Exception ex)
{
_outcome = "Error Occured";
context.JournalData.Add("Exception", ex.Message);
context.WorkflowInstance.Fault = new Elsa.Models.WorkflowFault(null, "Exception occured at activity level", context.ActivityId.ToString(), context.Input, context.Resuming);
}
```

In this case Workflow status is "**Finished**" and Activity Status is "**Executed**"
![image](https://user-images.githubusercontent.com/67507118/150674466-a133eb68-b747-4535-a3d3-d6f424550af7.png)

![image](https://user-images.githubusercontent.com/67507118/150674508-39e1d73e-8a4f-400b-8e23-f6039790ad8b.png)

![image](https://user-images.githubusercontent.com/67507118/150674489-b1247a18-98c9-4259-ab55-85cc66cb7cf8.png)

So Please suggest the best practice/ approach to use the activity failed state using above approach.
Also, if any alternative better idea please suggest as well for the same.

_Originally posted by @jayachandra21 in https://github.com/elsa-workflows/elsa-core/discussions/2687_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.