mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
refactor(source-maps): report decoder failures through ParseFailure (#10690)
SourceMapFormatFailure and its format/unsupported/limit/section-overlap reasons are replaced by ParseFailureError with format source-map. Limits carry the selected allowance name and maximum; a section-boundary overlap is a malformed failure on the section-boundary field. The codec reply protocol and every public error are unchanged.
This commit is contained in:
1 parent
6f19681551
commit
133e7762b6
8 files changed
+203
-114
No files matched your search
@@ -5,7 +5,12 @@ import {
|
||||
sourceMapLimitsSchema,
|
||||
} from "../../domain/sourceMapLimits.js";
|
||||
import { traceSourceMap } from "./TraceSourceMap.js";
|
||||
import { SourceMapFormatFailure } from "./SourceMapFormat.js";
|
||||
import {
|
||||
isSourceMapFailure,
|
||||
SOURCE_MAP_FORMAT,
|
||||
sourceMapLimitFailure,
|
||||
} from "./SourceMapFormat.js";
|
||||
import { malformedInput } from "../../domain/parseFailure.js";
|
||||
import {
|
||||
sourceMapCodecInputSchema,
|
||||
sourceMapCodecReplySchema,
|
||||
@@ -17,10 +22,7 @@ const execute = async (): Promise<string> => {
|
||||
try {
|
||||
const path = process.argv[2];
|
||||
if (path === undefined)
|
||||
throw new SourceMapFormatFailure(
|
||||
"format",
|
||||
"Codec request path is missing.",
|
||||
);
|
||||
throw malformedInput(SOURCE_MAP_FORMAT, "Codec request path is missing.");
|
||||
const selected = sourceMapLimitsSchema.parse(
|
||||
JSON.parse(process.argv[3] ?? "{}"),
|
||||
);
|
||||
@@ -30,9 +32,10 @@ const execute = async (): Promise<string> => {
|
||||
const value: unknown = JSON.parse(text);
|
||||
const input = sourceMapCodecInputSchema.parse(value);
|
||||
if (Buffer.byteLength(input.text) > limits.mapBytes)
|
||||
throw new SourceMapFormatFailure(
|
||||
"limit",
|
||||
`Source map exceeds codec input admission. ${sourceMapLimitRecovery("map_bytes", limits.mapBytes)}`,
|
||||
throw sourceMapLimitFailure(
|
||||
`Source map exceeds codec input admission.`,
|
||||
"map_bytes",
|
||||
limits.mapBytes,
|
||||
);
|
||||
const report = traceSourceMap(
|
||||
input.text,
|
||||
@@ -44,15 +47,16 @@ const execute = async (): Promise<string> => {
|
||||
sourceMapCodecReplySchema.parse({ state: "success", report }),
|
||||
);
|
||||
if (Buffer.byteLength(reply) > limits.outputBytes)
|
||||
throw new SourceMapFormatFailure(
|
||||
"limit",
|
||||
`Complete source-map point evidence exceeds output admission; no partial evidence was returned. ${sourceMapLimitRecovery("output_bytes", limits.outputBytes)}`,
|
||||
throw sourceMapLimitFailure(
|
||||
`Complete source-map point evidence exceeds output admission; no partial evidence was returned.`,
|
||||
"output_bytes",
|
||||
limits.outputBytes,
|
||||
);
|
||||
return reply;
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
!(
|
||||
cause instanceof SourceMapFormatFailure ||
|
||||
isSourceMapFailure(cause) ||
|
||||
cause instanceof z.ZodError ||
|
||||
cause instanceof SyntaxError
|
||||
)
|
||||
@@ -61,10 +65,11 @@ const execute = async (): Promise<string> => {
|
||||
return JSON.stringify({
|
||||
state: "failure",
|
||||
reason:
|
||||
cause instanceof SourceMapFormatFailure &&
|
||||
cause.reason !== "section-overlap"
|
||||
? cause.reason
|
||||
: "format",
|
||||
!isSourceMapFailure(cause) ||
|
||||
cause.kind === "malformed" ||
|
||||
cause.kind === "truncated"
|
||||
? "format"
|
||||
: cause.kind,
|
||||
message: cause.message,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user