jackwener/OpenCLI · error · ArgumentError
封面文件不存在: ${path.resolve(coverPath)}
Error message
封面文件不存在: ${path.resolve(coverPath)} What it means
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.
Source
Thrown at clis/douyin/draft.js:326
if (!fs.existsSync(videoPath)) {
throw new ArgumentError(`视频文件不存在: ${videoPath}`);
}
const ext = path.extname(videoPath).toLowerCase();
if (!['.mp4', '.mov', '.avi', '.webm'].includes(ext)) {
throw new ArgumentError(`不支持的视频格式: ${ext}(支持 mp4/mov/avi/webm)`);
}
const title = kwargs.title;
if (title.length > 30) {
throw new ArgumentError('标题不能超过 30 字');
}
const caption = kwargs.caption || '';
if (caption.length > 1000) {
throw new ArgumentError('正文不能超过 1000 字');
}
const coverPath = kwargs.cover;
if (coverPath) {
if (!fs.existsSync(path.resolve(coverPath))) {
throw new ArgumentError(`封面文件不存在: ${path.resolve(coverPath)}`);
}
}
if (!page.setFileInput) {
throw new CommandExecutionError('当前浏览器适配器不支持文件注入', '请使用 Browser Bridge 或支持 setFileInput 的浏览器模式');
}
const visibilityLabel = VISIBILITY_LABELS[kwargs.visibility] ?? VISIBILITY_LABELS.public;
await page.goto(DRAFT_UPLOAD_URL);
await page.wait({ selector: 'input[type="file"]', timeout: 20 });
await dismissKnownModals(page);
await page.setFileInput([videoPath], 'input[type="file"]');
await waitForDraftComposer(page);
await dismissKnownModals(page);
if (coverPath) {
const coverSelector = await prepareCustomCoverInput(page);
await page.setFileInput([path.resolve(coverPath)], coverSelector);
await waitForCoverReady(page);
}
await fillDraftComposer(page, { title, caption, visibilityLabel });View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
await cli.draft({ video: 'v.mp4', cover: './cover.jpg' }); // cwd mismatch
// after
await cli.draft({ video: 'v.mp4', cover: path.resolve(__dirname, 'cover.jpg') }); Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
const coverPath = path.resolve(cover);
if (cover && !fs.existsSync(coverPath)) throw new Error(`Cover missing: ${coverPath}`); Try / catch
try {
await cli.draft({ cover, video, title });
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('封面文件不存在')) {
console.error('Generate the cover first or omit --cover');
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- Media file not found: ${resolved}
- ${label}文件不存在: ${resolved}
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c82bd1cd6cca8d67.
Report an issue: GitHub.