-
Notifications
You must be signed in to change notification settings - Fork 26
Avoid throwing System.Exception in FailTaskAsync #767
Copy link
Copy link
Labels
C#C# related codeC# related codeMaintainabilitybugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededrefactoringRefactoring codeRefactoring code
Description
What version of FlowSynx?
1.2.5
Describe the bug
File: src/FlowSynx.Infrastructure/Workflow/WorkflowTaskExecutor.cs
Method: FailTaskAsync
In the FailTaskAsync method, the current implementation throws a generic System.Exception:
private async Task FailTaskAsync(
string userId,
WorkflowTaskExecutionEntity entity,
Exception ex,
CancellationToken cancellationToken,
string taskName)
{
await CompleteTaskAsync(userId, entity, WorkflowTaskExecutionStatus.Failed, cancellationToken);
_logger.LogError(ex, "Workflow task '{TaskName}' failed: {Message}", taskName, ex.Message);
throw new Exception(ex.Message, ex);
}Throwing System.Exception directly in user code is discouraged because it is too generic, making it harder for consumers to handle errors properly and understand the failure context.
Proposed Fix:
private async Task FailTaskAsync(
string userId,
WorkflowTaskExecutionEntity entity,
Exception ex,
CancellationToken cancellationToken,
string taskName)
{
await CompleteTaskAsync(userId, entity, WorkflowTaskExecutionStatus.Failed, cancellationToken);
_logger.LogError(ex, "Workflow task '{TaskName}' failed: {Message}", taskName, ex.Message);
throw new InvalidOperationException($"Workflow task '{taskName}' failed.", ex);
}Benefits:
- Provides a clear, meaningful exception type for consumers.
- Improves maintainability and readability of exception handling.
- Supports proper exception filtering in try/catch blocks.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C#C# related codeC# related codeMaintainabilitybugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededrefactoringRefactoring codeRefactoring code