Say why a cookies file or the clips folder can't be used

"Couldn't read the cookies file" covered both a file the service
can't read and a clips folder it can't write its copy into. Each now
has its own message naming the setting (YTDLP_COOKIES or CLIPS_DIR)
and the cause: missing, or not allowed for the service's user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-28 03:51:31 -05:00
parent 7e501a3aca
commit 09294eb7ce

View file

@ -49,7 +49,7 @@
import { spawn } from "node:child_process";
import { randomBytes } from "node:crypto";
import { copyFile, mkdir, readdir, rm, stat } from "node:fs/promises";
import { access, constants, copyFile, mkdir, readdir, rm, stat } from "node:fs/promises";
import path from "node:path";
import { UPLOADS_DIR, PUBLIC_PREFIX } from "./media.js";
@ -251,12 +251,27 @@ function update(db, id, fields) {
async function cookieArgs(jobId) {
if (COOKIES_FILE) {
const copy = path.join(CLIPS_DIR, `.cookies-${jobId}.txt`);
// Two steps, so a failure names the right one: reading the
// original, or writing the copy into CLIPS_DIR.
try {
await access(COOKIES_FILE, constants.R_OK);
} catch (err) {
const why =
err.code === "ENOENT"
? "it isn't there"
: err.code === "EACCES"
? "the service's user isn't allowed to read it (check its owner and permissions)"
: err.code;
throw new Error(`Couldn't read the cookies file at ${COOKIES_FILE} (YTDLP_COOKIES): ${why}.`);
}
try {
await copyFile(COOKIES_FILE, copy);
} catch (err) {
throw new Error(
`Couldn't read the cookies file at ${COOKIES_FILE} (YTDLP_COOKIES)${err.code === "ENOENT" ? ": it isn't there" : ""}.`,
);
const why =
err.code === "EACCES" || err.code === "EPERM"
? "the service's user isn't allowed to write there"
: err.code;
throw new Error(`Couldn't copy the cookies file into ${CLIPS_DIR} (CLIPS_DIR): ${why}.`);
}
return { args: ["--cookies", copy], cleanup: () => rm(copy, { force: true }) };
}
@ -427,7 +442,13 @@ export function kick(db = dbRef) {
(async () => {
try {
await mkdir(CLIPS_DIR, { recursive: true });
await mkdir(CLIPS_DIR, { recursive: true }).catch((err) => {
throw new Error(
`Couldn't use the working folder ${CLIPS_DIR} (CLIPS_DIR): ${
err.code === "EACCES" || err.code === "EPERM" ? "the service's user isn't allowed to write there" : err.code
}.`,
);
});
if (job.kind === "source") await download(db, job);
else await cut(db, job);
update(db, job.id, { status: "done", progress: 1, finished_at: new Date().toISOString() });