mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
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:
@@ -1,3 +1,4 @@
|
||||
import { ToolInputError } from "@snapotter/shared";
|
||||
import type { CropOptions, Sharp } from "../types.js";
|
||||
|
||||
export async function crop(image: Sharp, options: CropOptions): Promise<Sharp> {
|
||||
@@ -23,19 +24,19 @@ export async function crop(image: Sharp, options: CropOptions): Promise<Sharp> {
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
throw new Error("Crop width and height must be greater than 0");
|
||||
throw new ToolInputError("Crop width and height must be greater than 0");
|
||||
}
|
||||
if (left < 0 || top < 0) {
|
||||
throw new Error("Crop left and top must be non-negative");
|
||||
throw new ToolInputError("Crop left and top must be non-negative");
|
||||
}
|
||||
|
||||
if (left + width > imgWidth) {
|
||||
throw new Error(
|
||||
throw new ToolInputError(
|
||||
`Crop region exceeds image width: left(${left}) + width(${width}) > ${imgWidth}`,
|
||||
);
|
||||
}
|
||||
if (top + height > imgHeight) {
|
||||
throw new Error(
|
||||
throw new ToolInputError(
|
||||
`Crop region exceeds image height: top(${top}) + height(${height}) > ${imgHeight}`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user