Skip to content

Commit 25e4197

Browse files
committed
simplify error name declaration
1 parent 04823f0 commit 25e4197

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/array_result.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ export type ArrayResultOptions = {
66
};
77
export class ArrayResultError extends Error {
88
isHtml: boolean;
9+
override name = "ArrayResultError";
910
constructor(message: string, options: Partial<ArrayResultOptions> = {}) {
1011
super(message, { cause: options.cause });
1112
this.isHtml = options.isHtml ?? false;
12-
this.name = "ArrayResultError";
1313
}
1414
}
1515
export class TodoError extends ArrayResultError {
16+
override name = "TodoError";
1617
constructor(functionality: string) {
1718
super(`${functionality} is not yet implemented`);
18-
this.name = "TodoError";
1919
}
2020
}
2121
export class ArrayResult<const T> {

src/parser/parser_lib.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ export class Parser<const T> {
8484
export type Position = Readonly<{ position: number; length: number }>;
8585
export class PositionedError extends ArrayResultError {
8686
public position: null | Position;
87+
override name = "PositionedError";
8788
constructor(message: string, position?: Position) {
8889
super(message);
8990
this.position = position ?? null;
90-
this.name = "PositionedError";
9191
}
9292
}
9393
function withPositionedError<const T>(fn: () => T, position: Position) {
@@ -102,18 +102,18 @@ function withPositionedError<const T>(fn: () => T, position: Position) {
102102
}
103103
}
104104
export class UnexpectedError extends PositionedError {
105+
override name = "UnexpectedError";
105106
constructor(unexpected: string, expected: string, position?: Position) {
106107
super(
107108
`unexpected ${unexpected}. ${expected} were expected instead`,
108109
position,
109110
);
110-
this.name = "UnexpectedError";
111111
}
112112
}
113113
export class UnrecognizedError extends PositionedError {
114+
override name = "UnrecognizedError";
114115
constructor(element: string, position?: Position) {
115116
super(`${element} is unrecognized`, position);
116-
this.name = "UnrecognizedError";
117117
}
118118
}
119119
export function error(error: ArrayResultError): Parser<never> {

src/translator/error.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { ArrayResultError, TodoError } from "../array_result.ts";
22

33
export class TranslationTodoError extends TodoError {
4+
override name = "TranslationTodoError";
45
constructor(type: string) {
56
super(`translation of ${type}`);
6-
this.name = "TranslationTodoError";
77
}
88
}
99
export class ExhaustedError extends ArrayResultError {
10+
override name = "ExhaustedError";
1011
constructor(text: string) {
1112
super(`no possible translation found for "${text}"`);
12-
this.name = "ExhaustedError";
1313
}
1414
}
1515
export class FilteredError extends ArrayResultError {
16+
override name = "FilteredOutError";
1617
constructor(element: string) {
1718
super(`${element} is filtered out`);
18-
this.name = "FilteredOutError";
1919
}
2020
}
2121
export class UntranslatableError extends ArrayResultError {
22+
override name = "UntranslatableError";
2223
constructor(source: string, target: string) {
2324
super(`cannot translate ${source} into ${target}`);
24-
this.name = "UntranslatableError";
2525
}
2626
}

0 commit comments

Comments
 (0)