Skip to content

Commit d593bbd

Browse files
committed
Throw recognizable errors
1 parent f4521c3 commit d593bbd

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/error.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class CypressCucumberError extends Error {}

lib/registry.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { assertAndReturn } from "./assertions";
1414

1515
import DataTable from "./data_table";
1616

17+
import { CypressCucumberError } from "./error";
18+
1719
import {
1820
IHookBody,
1921
IParameterTypeDefinition,
@@ -25,6 +27,10 @@ interface IStepDefinition<T extends unknown[]> {
2527
implementation: IStepDefinitionBody<T>;
2628
}
2729

30+
export class MissingDefinitionError extends CypressCucumberError {}
31+
32+
export class MultipleDefinitionsError extends CypressCucumberError {}
33+
2834
export type HookKeyword = "Before" | "After";
2935

3036
export interface IHook {
@@ -131,9 +137,11 @@ export class Registry {
131137
);
132138

133139
if (matchingStepDefinitions.length === 0) {
134-
throw new Error(`Step implementation missing for: ${text}`);
140+
throw new MissingDefinitionError(
141+
`Step implementation missing for: ${text}`
142+
);
135143
} else if (matchingStepDefinitions.length > 1) {
136-
throw new Error(
144+
throw new MultipleDefinitionsError(
137145
`Multiple matching step definitions for: ${text}\n` +
138146
matchingStepDefinitions
139147
.map((stepDefinition) => {

0 commit comments

Comments
 (0)