Skip to content

Commit d41fd27

Browse files
committed
only cache array result errors
1 parent 2b6f4af commit d41fd27

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/array_result.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ export function extractArrayResultError(
173173
}
174174
}
175175
}
176+
export function isArrayResult(errors: ReadonlyArray<unknown>): boolean {
177+
return errors.length > 0 &&
178+
errors.every((error) => error instanceof ArrayResultError);
179+
}

src/main.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (typeof LIVE_RELOAD !== "undefined" && LIVE_RELOAD) {
1212
import { dictionary } from "../dictionary/dictionary.ts";
1313
import { asComment } from "../dictionary/misc.ts";
1414
import PROJECT_DATA from "../project_data.json" with { type: "json" };
15-
import { ArrayResultError } from "./array_result.ts";
15+
import { ArrayResultError, isArrayResult } from "./array_result.ts";
1616
import { loadCustomDictionary } from "./dictionary.ts";
1717
import { checkLocalStorage, setIgnoreError } from "./local_storage.ts";
1818
import { flattenError } from "../misc/misc.ts";
@@ -144,7 +144,7 @@ function main(): void {
144144
try {
145145
loadCustomDictionary(customDictionary);
146146
} catch (error) {
147-
errorDisplay.innerText = errorsFixable(flattenError(error))
147+
errorDisplay.innerText = isArrayResult(flattenError(error))
148148
? DICTIONARY_LOADING_FAILED_FIXABLE_MESSAGE
149149
: DICTIONARY_LOADING_FAILED_UNFIXABLE_MESSAGE;
150150
// deno-lint-ignore no-console
@@ -276,7 +276,7 @@ function main(): void {
276276
customDictionaryDialogBox.close();
277277
} catch (error) {
278278
const errors = flattenError(error);
279-
const message = errorsFixable(errors)
279+
const message = isArrayResult(errors)
280280
? DICTIONARY_ERROR_FIXABLE_MESSAGE
281281
: DICTIONARY_ERROR_UNFIXABLE_MESSAGE;
282282
const errorListMessage = errors
@@ -300,10 +300,6 @@ function extractErrorMessage(error: unknown): string {
300300
return `${error}`;
301301
}
302302
}
303-
function errorsFixable(errors: ReadonlyArray<unknown>): boolean {
304-
return errors.length > 0 &&
305-
errors.every((error) => error instanceof ArrayResultError);
306-
}
307303

308304
if (document.readyState === "loading") {
309305
document.addEventListener("DOMContentLoaded", main);

src/parser/parser_lib.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { assert } from "@std/assert/assert";
22
import { MemoizationCacheResult, memoize } from "@std/cache/memoize";
3-
import { ArrayResult, ArrayResultError } from "../array_result.ts";
3+
import {
4+
ArrayResult,
5+
ArrayResultError,
6+
isArrayResult,
7+
} from "../array_result.ts";
48
import { Clearable, ClearableCacheSet, Lazy } from "../cache.ts";
5-
import { throwError } from "../../misc/misc.ts";
9+
import { flattenError, throwError } from "../../misc/misc.ts";
610

711
export type ValueRest<T> = Readonly<{ rest: string; value: T }>;
812
export type ParserResult<T> = ArrayResult<ValueRest<T>>;
@@ -18,7 +22,7 @@ export class Parser<T> {
1822
Parser.addToCache(cache);
1923
this.rawParser = memoize(this.nonMemoizedParser, {
2024
cache,
21-
errorIsCacheable: () => true,
25+
errorIsCacheable: (error) => isArrayResult(flattenError(error)),
2226
});
2327
} else {
2428
this.rawParser = this.nonMemoizedParser;

0 commit comments

Comments
 (0)