Skip to content

Commit 99aa90e

Browse files
committed
feat(exhaustive): rename thrown error to NonExhaustiveError
1 parent b2e7566 commit 99aa90e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Error when the given input value does not match any included pattern
33
* and .exhaustive() was specified
44
*/
5-
export class ExhaustiveError extends Error {
5+
export class NonExhaustiveError extends Error {
66
constructor(public input: unknown) {
77
let displayedValue;
88
try {

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ import * as Pattern from './patterns';
33
export { match } from './match';
44
export { isMatching } from './is-matching';
55
export { Pattern, Pattern as P };
6-
export { ExhaustiveError } from './errors';
6+
export { NonExhaustiveError } from './errors';

src/match.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Pattern } from './types/Pattern';
22
import { Match } from './types/Match';
33
import * as symbols from './internals/symbols';
44
import { matchPattern } from './internals/helpers';
5-
import { ExhaustiveError } from './errors';
5+
import { NonExhaustiveError } from './errors';
66

77
type MatchState<output> =
88
| { matched: true; value: output }
@@ -115,7 +115,7 @@ class MatchExpression<input, output> {
115115
exhaustive(): output {
116116
if (this.state.matched) return this.state.value;
117117

118-
throw new ExhaustiveError(this.input);
118+
throw new NonExhaustiveError(this.input);
119119
}
120120

121121
run(): output {

tests/exhaustive-match.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExhaustiveError, match, P } from '../src';
1+
import { NonExhaustiveError, match, P } from '../src';
22
import { Equal, Expect } from '../src/types/helpers';
33
import {
44
Option,
@@ -808,31 +808,31 @@ describe('exhaustive()', () => {
808808
.exhaustive();
809809
}
810810

811-
it('Unmatched pattern results in ExhaustiveError', () => {
811+
it('Unmatched pattern results in NonExhaustiveError', () => {
812812
expect.assertions(3);
813813
const input = { color: 'orange' } as unknown as FlagComponent;
814814

815815
try {
816816
checkFlagComponent(input);
817817
} catch (e) {
818-
const err = e as ExhaustiveError;
819-
expect(err).toBeInstanceOf(ExhaustiveError);
818+
const err = e as NonExhaustiveError;
819+
expect(err).toBeInstanceOf(NonExhaustiveError);
820820
expect(err.message).toEqual(
821821
'Pattern matching error: no pattern matches value {"color":"orange"}'
822822
);
823823
expect(err.input).toStrictEqual(input);
824824
}
825825
});
826826

827-
it('Matched pattern with callback error does not result in ExhaustiveError', () => {
827+
it('Matched pattern with callback error does not result in NonExhaustiveError', () => {
828828
expect.assertions(3);
829829

830830
try {
831831
checkFlagComponent({ color: 'blue' });
832832
} catch (e) {
833833
const err = e as Error;
834834
expect(err).toBeInstanceOf(Error);
835-
expect(err).not.toBeInstanceOf(ExhaustiveError);
835+
expect(err).not.toBeInstanceOf(NonExhaustiveError);
836836
expect(err.message).toEqual('Blue error');
837837
}
838838
});

0 commit comments

Comments
 (0)