From 09294eb7cea1173f75fcb6a8974b38fd97866f7f Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Mon, 28 Sep 2026 03:51:31 -0500 Subject: [PATCH] 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 --- server/src/clips.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/server/src/clips.js b/server/src/clips.js index 296ceaa..508bec6 100644 --- a/server/src/clips.js +++ b/server/src/clips.js @@ -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() });