{"record":{"id":"c82bd1cd6cca8d67","repo":"jackwener/OpenCLI","slug":"path-resolve-coverpath","errorCode":null,"errorMessage":"封面文件不存在: ${path.resolve(coverPath)}","messagePattern":"封面文件不存在: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/douyin/draft.js","lineNumber":326,"sourceCode":"        if (!fs.existsSync(videoPath)) {\n            throw new ArgumentError(`视频文件不存在: ${videoPath}`);\n        }\n        const ext = path.extname(videoPath).toLowerCase();\n        if (!['.mp4', '.mov', '.avi', '.webm'].includes(ext)) {\n            throw new ArgumentError(`不支持的视频格式: ${ext}（支持 mp4/mov/avi/webm）`);\n        }\n        const title = kwargs.title;\n        if (title.length > 30) {\n            throw new ArgumentError('标题不能超过 30 字');\n        }\n        const caption = kwargs.caption || '';\n        if (caption.length > 1000) {\n            throw new ArgumentError('正文不能超过 1000 字');\n        }\n        const coverPath = kwargs.cover;\n        if (coverPath) {\n            if (!fs.existsSync(path.resolve(coverPath))) {\n                throw new ArgumentError(`封面文件不存在: ${path.resolve(coverPath)}`);\n            }\n        }\n        if (!page.setFileInput) {\n            throw new CommandExecutionError('当前浏览器适配器不支持文件注入', '请使用 Browser Bridge 或支持 setFileInput 的浏览器模式');\n        }\n        const visibilityLabel = VISIBILITY_LABELS[kwargs.visibility] ?? VISIBILITY_LABELS.public;\n        await page.goto(DRAFT_UPLOAD_URL);\n        await page.wait({ selector: 'input[type=\"file\"]', timeout: 20 });\n        await dismissKnownModals(page);\n        await page.setFileInput([videoPath], 'input[type=\"file\"]');\n        await waitForDraftComposer(page);\n        await dismissKnownModals(page);\n        if (coverPath) {\n            const coverSelector = await prepareCustomCoverInput(page);\n            await page.setFileInput([path.resolve(coverPath)], coverSelector);\n            await waitForCoverReady(page);\n        }\n        await fillDraftComposer(page, { title, caption, visibilityLabel });","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/draft.js#L308-L344","documentation":"When a cover image path is provided via kwargs.cover, the command checks fs.existsSync on the resolved absolute path. If the file is missing, an ArgumentError is thrown with the resolved path included to help locate the mismatch.","triggerScenarios":"Calling `douyin draft --cover <path>` where the cover file does not exist at the resolved absolute path — typo, wrong working directory, deleted file, or a relative path resolved from an unexpected cwd.","commonSituations":"Relative paths run from a different working directory (cron/CI), cover generated in a temp dir that was cleaned up, wrong extension (.png vs .jpg), or forgot to export the cover from an editor.","solutions":["Verify the file exists: `ls -l <resolved path shown in the error>`","Pass an absolute path to avoid cwd-dependent resolution","Generate/export the cover image first, or omit --cover to let the platform pick a frame"],"exampleFix":"// before\nawait cli.draft({ video: 'v.mp4', cover: './cover.jpg' }); // cwd mismatch\n// after\nawait cli.draft({ video: 'v.mp4', cover: path.resolve(__dirname, 'cover.jpg') });","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst coverPath = path.resolve(cover);\nif (cover && !fs.existsSync(coverPath)) throw new Error(`Cover missing: ${coverPath}`);","typeGuard":null,"tryCatchPattern":"try {\n  await cli.draft({ cover, video, title });\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('封面文件不存在')) {\n    console.error('Generate the cover first or omit --cover');\n  } else throw e;\n}","preventionTips":["Always pass absolute paths (path.resolve) — CLI resolution depends on process cwd","Generate/export the cover image before the draft step in your pipeline","Add an fs.existsSync check in scripts wrapping the CLI"],"tags":["validation","file-not-found","argument-error"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}