Skip to content

Commit a317db0

Browse files
minor improvement of 'assertUnreachable', contributed 'assertCondition' to error.ts (#1940)
1 parent b55aaf2 commit a317db0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/langium/src/utils/errors.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class ErrorWithLocation extends Error {
1212
}
1313
}
1414

15-
export function assertUnreachable(_: never): never {
16-
throw new Error('Error! The input value was not handled.');
15+
export function assertUnreachable(_: never, message = 'Error: Got unexpected value.'): never {
16+
throw new Error(message);
17+
}
18+
19+
export function assertCondition(condition: boolean, message: string = 'Error: Condition is violated.'): asserts condition {
20+
if (!condition) {
21+
throw new Error(message);
22+
}
1723
}

0 commit comments

Comments
 (0)