mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(api): drop app-logger import from media-input; update stale errors mock
The full unit suite surfaced two issues from earlier commits on this branch. (1) Importing the app logger into media-input.ts pulled logger.ts -- which builds its pino file transport at module load via join(env.LOG_DIR, ...) -- into the unit-test import graph, throwing at collection time wherever LOG_DIR is unset (integration tests set it; unit tests do not). A low-level modality handler should not depend on the app logger, and a corrupt upload is an expected user error, so drop the import and keep the clean validation message. (2) tool-factory-route.test.ts mocked errors.js without the new friendlyError export; add it.
This commit is contained in:
@@ -4,7 +4,6 @@ import { extname, join } from "node:path";
|
|||||||
import { probeMedia } from "@snapotter/media-engine";
|
import { probeMedia } from "@snapotter/media-engine";
|
||||||
import { SUBTITLE_INPUTS } from "@snapotter/shared";
|
import { SUBTITLE_INPUTS } from "@snapotter/shared";
|
||||||
import { env } from "../config.js";
|
import { env } from "../config.js";
|
||||||
import { logger } from "../lib/logger.js";
|
|
||||||
import { type InputHandler, InputValidationError, type PreparedInput } from "./contract.js";
|
import { type InputHandler, InputValidationError, type PreparedInput } from "./contract.js";
|
||||||
|
|
||||||
export type MediaInputKind = "video" | "audio" | "image" | "subtitle";
|
export type MediaInputKind = "video" | "audio" | "image" | "subtitle";
|
||||||
@@ -38,9 +37,10 @@ export class MediaInputHandler implements InputHandler {
|
|||||||
let info: Awaited<ReturnType<typeof probeMedia>>;
|
let info: Awaited<ReturnType<typeof probeMedia>>;
|
||||||
try {
|
try {
|
||||||
info = await probeMedia(probePath);
|
info = await probeMedia(probePath);
|
||||||
} catch (err) {
|
} catch {
|
||||||
// Keep the raw ffprobe failure in logs; never surface it to the client.
|
// ffprobe could not parse the upload. Surface a clean message; the raw
|
||||||
logger.warn({ err, kind: this.kind }, "media input probe failed");
|
// tool error is intentionally not exposed to the client, and a bad
|
||||||
|
// upload is not a server fault worth logging from this low-level handler.
|
||||||
throw new InputValidationError(
|
throw new InputValidationError(
|
||||||
`Unrecognized ${this.kind} file. It may be corrupt or in an unsupported format.`,
|
`Unrecognized ${this.kind} file. It may be corrupt or in an unsupported format.`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ vi.mock("@snapotter/doc-engine", () => ({
|
|||||||
vi.mock("../../../apps/api/src/lib/errors.js", () => ({
|
vi.mock("../../../apps/api/src/lib/errors.js", () => ({
|
||||||
formatZodErrors: (issues: Array<{ message: string }>) => issues.map((i) => i.message).join("; "),
|
formatZodErrors: (issues: Array<{ message: string }>) => issues.map((i) => i.message).join("; "),
|
||||||
stripInternalPaths: (msg: string) => msg,
|
stripInternalPaths: (msg: string) => msg,
|
||||||
|
friendlyError: (msg: string) => msg,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("sharp", () => ({
|
vi.mock("sharp", () => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user