fix(tools): classify expected input and timeout errors, not bugs (#539)

crop/merge-pdf/csv bad input -> ToolInputError/InputValidationError (expected, 4xx); ffmpeg timeout -> operational SafeError. Internal v2-only guards stay plain Errors.
This commit is contained in:
SnapOtter
2026-07-16 19:26:18 +08:00
committed by GitHub
parent 55e1e95f20
commit 39b89b9fbd
6 changed files with 62 additions and 13 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
import { spawn } from "node:child_process";
import { markToolInputError } from "@snapotter/shared";
import { markToolInputError, SafeError } from "@snapotter/shared";
import { resolveFfmpeg } from "./binaries.js";
import { type FfmpegProgress, parseProgressBlock } from "./progress.js";
@@ -48,7 +48,7 @@ export async function runFfmpeg(args: string[], opts: RunFfmpegOptions = {}): Pr
const timeoutMs = opts.timeoutMs;
const timer = timeoutMs
? setTimeout(() => {
fail(new Error(`ffmpeg timed out after ${Math.round(timeoutMs / 1000)}s`));
fail(new SafeError("ffmpeg timed out", { kind: "operational", code: "timeout" }));
}, timeoutMs)
: undefined;
const onAbort = () => fail(new Error("Canceled"));