mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
refactor(errors): finish local-limit-error-class and range-error-interpretation guards (#11784)
This commit is contained in:
1 parent
62f5946ba1
commit
08b63cc8a1
21 files changed
+208
-103
No files matched your search
@@ -1,13 +1,45 @@
|
||||
import { decodeLimit, ParseFailureError } from "../domain/parseFailure.js";
|
||||
import type { V8CodeCacheInputBudget } from "../domain/v8/v8CodeCacheBudget.js";
|
||||
|
||||
/** A caller-selected budget was exceeded while scanning the payload. */
|
||||
export class V8CodeCacheBudgetFailure extends Error {
|
||||
constructor(
|
||||
readonly boundary: keyof V8CodeCacheInputBudget,
|
||||
readonly limit: number,
|
||||
message: string,
|
||||
) {
|
||||
super(message);
|
||||
this.name = "V8CodeCacheBudgetFailure";
|
||||
}
|
||||
/** The ParseFailure format of V8 code cache containers. */
|
||||
export const V8_CODE_CACHE_FORMAT = "v8-code-cache";
|
||||
|
||||
export type V8CodeCacheBudgetBoundary = keyof V8CodeCacheInputBudget;
|
||||
|
||||
export interface V8CodeCacheBudgetLimit {
|
||||
readonly boundary: V8CodeCacheBudgetBoundary;
|
||||
readonly limit: number;
|
||||
readonly message: string;
|
||||
}
|
||||
|
||||
const V8_CODE_CACHE_BUDGET_BOUNDARIES = new Set<V8CodeCacheBudgetBoundary>([
|
||||
"max_strings",
|
||||
"min_string_bytes",
|
||||
]);
|
||||
|
||||
/** A caller-selected budget was exceeded while scanning the payload. */
|
||||
export const v8CodeCacheBudgetFailure = (
|
||||
boundary: V8CodeCacheBudgetBoundary,
|
||||
limit: number,
|
||||
message: string,
|
||||
): ParseFailureError<"limit"> =>
|
||||
decodeLimit(V8_CODE_CACHE_FORMAT, message, {
|
||||
name: boundary,
|
||||
maximum: limit,
|
||||
});
|
||||
|
||||
export const v8CodeCacheBudgetLimitOf = (
|
||||
cause: unknown,
|
||||
): V8CodeCacheBudgetLimit | undefined =>
|
||||
cause instanceof ParseFailureError &&
|
||||
cause.failure.kind === "limit" &&
|
||||
cause.failure.format === V8_CODE_CACHE_FORMAT &&
|
||||
V8_CODE_CACHE_BUDGET_BOUNDARIES.has(
|
||||
cause.failure.limit.name as V8CodeCacheBudgetBoundary,
|
||||
)
|
||||
? {
|
||||
boundary: cause.failure.limit.name as V8CodeCacheBudgetBoundary,
|
||||
limit: cause.failure.limit.maximum,
|
||||
message: cause.failure.detail,
|
||||
}
|
||||
: undefined;
|
||||
Reference in new issue
Block a user