Skip to content

Commit 876d9a2

Browse files
committed
cleanup exceptions
1 parent 7eb8378 commit 876d9a2

File tree

12 files changed

+47
-17
lines changed

12 files changed

+47
-17
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Exceptions
6+
{
7+
public class CorruptPersistenceDataException : Exception
8+
{
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace WorkflowCore.Exceptions
6+
{
7+
public class WorkflowNotRegisteredException : Exception
8+
{
9+
public WorkflowNotRegisteredException(string workflowId, int? version)
10+
: base($"Workflow {workflowId} {version} is not registered")
11+
{
12+
}
13+
}
14+
}

src/WorkflowCore/Primitives/If.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66
using System.Text;
7+
using WorkflowCore.Exceptions;
78
using WorkflowCore.Interface;
89
using WorkflowCore.Models;
910

@@ -35,7 +36,7 @@ public override ExecutionResult Run(IStepExecutionContext context)
3536
return ExecutionResult.Persist(context.PersistenceData);
3637
}
3738

38-
throw new Exception("Corrupt persistence data");
39+
throw new CorruptPersistenceDataException();
3940
}
4041
}
4142
}

src/WorkflowCore/Primitives/OutcomeSwitch.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66
using System.Text;
7+
using WorkflowCore.Exceptions;
78
using WorkflowCore.Interface;
89
using WorkflowCore.Models;
910

@@ -36,7 +37,7 @@ public override ExecutionResult Run(IStepExecutionContext context)
3637
}
3738
}
3839

39-
throw new Exception("Corrupt persistence data");
40+
throw new CorruptPersistenceDataException();
4041
}
4142

4243
private object GetPreviousOutcome(IStepExecutionContext context)

src/WorkflowCore/Primitives/Sequence.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66
using System.Text;
7+
using WorkflowCore.Exceptions;
78
using WorkflowCore.Interface;
89
using WorkflowCore.Models;
910

@@ -28,7 +29,7 @@ public override ExecutionResult Run(IStepExecutionContext context)
2829
return ExecutionResult.Persist(context.PersistenceData);
2930
}
3031

31-
throw new Exception("Corrupt persistence data");
32+
throw new CorruptPersistenceDataException();
3233
}
3334
}
3435
}

src/WorkflowCore/Primitives/When.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66
using System.Text;
7+
using WorkflowCore.Exceptions;
78
using WorkflowCore.Interface;
89
using WorkflowCore.Models;
910

@@ -38,7 +39,7 @@ public override ExecutionResult Run(IStepExecutionContext context)
3839
return ExecutionResult.Persist(context.PersistenceData);
3940
}
4041

41-
throw new Exception("Corrupt persistence data");
42+
throw new CorruptPersistenceDataException();
4243
}
4344

4445
private object GetSwitchOutcome(IStepExecutionContext context)

src/WorkflowCore/Primitives/While.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq.Expressions;
66
using System.Text;
7+
using WorkflowCore.Exceptions;
78
using WorkflowCore.Interface;
89
using WorkflowCore.Models;
910

@@ -35,7 +36,7 @@ public override ExecutionResult Run(IStepExecutionContext context)
3536
return ExecutionResult.Persist(context.PersistenceData);
3637
}
3738

38-
throw new Exception("Corrupt persistence data");
39+
throw new CorruptPersistenceDataException();
3940
}
4041
}
4142
}

src/WorkflowCore/Services/FluentBuilders/StepBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ public IStepBuilder<TData, TStep> End<TStep>(string name) where TStep : IStepBod
145145
var ancestor = IterateParents(Step.Id, name);
146146

147147
if (ancestor == null)
148-
throw new Exception(String.Format("Parent step of name {0} not found", name));
148+
throw new InvalidOperationException($"Parent step of name {name} not found");
149149

150150
if (!(ancestor is WorkflowStep<TStep>))
151-
throw new Exception(String.Format("Parent step of name {0} is not of type {1}", name, typeof(TStep)));
151+
throw new InvalidOperationException($"Parent step of name {name} is not of type {typeof(TStep)}");
152152

153153
return new StepBuilder<TData, TStep>(WorkflowBuilder, (ancestor as WorkflowStep<TStep>));
154154
}

src/WorkflowCore/Services/WorkflowHost.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using WorkflowCore.Interface;
99
using WorkflowCore.Models;
1010
using System.Reflection;
11+
using WorkflowCore.Exceptions;
1112

1213
namespace WorkflowCore.Services
1314
{
@@ -61,11 +62,11 @@ public async Task<string> StartWorkflow<TData>(string workflowId, int? version,
6162
where TData : class
6263
{
6364
if (_shutdown)
64-
throw new Exception("Host is not running");
65+
throw new InvalidOperationException("Host is not running");
6566

6667
var def = Registry.GetDefinition(workflowId, version);
6768
if (def == null)
68-
throw new Exception(String.Format("Workflow {0} version {1} is not registered", workflowId, version));
69+
throw new WorkflowNotRegisteredException(workflowId, version);
6970

7071
var wf = new WorkflowInstance();
7172
wf.WorkflowDefinitionId = workflowId;
@@ -121,7 +122,7 @@ public void Stop()
121122
public async Task PublishEvent(string eventName, string eventKey, object eventData, DateTime? effectiveDate = null)
122123
{
123124
if (_shutdown)
124-
throw new Exception("Host is not running");
125+
throw new InvalidOperationException("Host is not running");
125126

126127
Logger.LogDebug("Creating event {0} {1}", eventName, eventKey);
127128
Event evt = new Event();

src/WorkflowCore/Services/WorkflowRegistry.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class WorkflowRegistry : IWorkflowRegistry
1111
{
1212

1313
private readonly IServiceProvider _serviceProvider;
14-
private List<Tuple<string, int, WorkflowDefinition>> _registry = new List<Tuple<string, int, WorkflowDefinition>>();
14+
private readonly List<Tuple<string, int, WorkflowDefinition>> _registry = new List<Tuple<string, int, WorkflowDefinition>>();
1515

1616
public WorkflowRegistry(IServiceProvider serviceProvider)
1717
{
@@ -40,7 +40,7 @@ public WorkflowDefinition GetDefinition(string workflowId, int? version = null)
4040
public void RegisterWorkflow(IWorkflow workflow)
4141
{
4242
if (_registry.Any(x => x.Item1 == workflow.Id && x.Item2 == workflow.Version))
43-
throw new Exception(String.Format("Workflow {0} version {1} is already registered", workflow.Id, workflow.Version));
43+
throw new InvalidOperationException($"Workflow {workflow.Id} version {workflow.Version} is already registered");
4444

4545
var builder = (_serviceProvider.GetService(typeof(IWorkflowBuilder)) as IWorkflowBuilder).UseData<object>();
4646
workflow.Build(builder);
@@ -52,7 +52,7 @@ public void RegisterWorkflow<TData>(IWorkflow<TData> workflow)
5252
where TData : new()
5353
{
5454
if (_registry.Any(x => x.Item1 == workflow.Id && x.Item2 == workflow.Version))
55-
throw new Exception(String.Format("Workflow {0} version {1} is already registed", workflow.Id, workflow.Version));
55+
throw new InvalidOperationException($"Workflow {workflow.Id} version {workflow.Version} is already registed");
5656

5757
var builder = (_serviceProvider.GetService(typeof(IWorkflowBuilder)) as IWorkflowBuilder).UseData<TData>();
5858
workflow.Build(builder);

0 commit comments

Comments
 (0)