jackwener/OpenCLI · error · ArgumentError
封面文件不存在: ${path.resolve(coverPath)}
Error message
封面文件不存在: ${path.resolve(coverPath)} What it means
When a cover image path (--cover) is supplied, publish.js checks existence synchronously with fs.existsSync(path.resolve(coverPath)) before uploading. If the resolved path does not exist on disk, it throws this ArgumentError immediately. The error includes the resolved absolute path to make the mismatch obvious.
Source
Thrown at clis/douyin/publish.js:136
if (!['.mp4', '.mov', '.avi', '.webm'].includes(ext)) {
throw new ArgumentError(`不支持的视频格式: ${ext}(支持 mp4/mov/avi/webm)`);
}
const fileSize = fs.statSync(videoPath).size;
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 timingTs = toUnixSeconds(kwargs.schedule);
validateTiming(timingTs);
const visibilityType = VISIBILITY_MAP[kwargs.visibility] ?? 0;
const coverPath = kwargs.cover;
if (coverPath) {
if (!fs.existsSync(path.resolve(coverPath))) {
throw new ArgumentError(`封面文件不存在: ${path.resolve(coverPath)}`);
}
}
// ── Phase 1: upload credentials ────────────────────────────────────
const credentials = await getUploadAuthV5Credentials(page);
// ── Phase 2: Apply TOS upload URL ───────────────────────────────────
const tosUploadInfo = await applyVideoUploadInner(fileSize, credentials);
let coverUri = '';
let coverWidth = 720;
let coverHeight = 1280;
// ── Phase 3: TOS upload ─────────────────────────────────────────────
await tosUpload({
filePath: videoPath,
uploadInfo: tosUploadInfo,
credentials,
onProgress: (uploaded, total) => {
const pct = Math.round((uploaded / total) * 100);
process.stderr.write(`\r 上传进度: ${pct}%`);
},View on GitHub (pinned to 49907e53dc)
Solutions
- Verify the file exists: run ls on the exact path passed to --cover
- Pass an absolute path (path.resolve) or run the CLI from the directory containing the cover
- Fix typos in the filename/extension and confirm case matches on case-sensitive filesystems
- Regenerate or re-export the cover image if a prior pipeline step failed to produce it
Example fix
// before
await douyin.publish({ cover: './cover.png' }); // run from wrong CWD
// after
import fs from 'fs';
import path from 'path';
const cover = path.resolve('./cover.png');
if (!fs.existsSync(cover)) throw new Error(`cover missing: ${cover}`);
await douyin.publish({ cover }); Defensive patterns
Strategy: validation
Validate before calling
import fs from 'fs';
import path from 'path';
const resolvedCover = path.resolve(kwargs.cover);
if (!fs.existsSync(resolvedCover) || !fs.statSync(resolvedCover).isFile()) {
throw new Error(`cover file missing: ${resolvedCover}`);
} Type guard
function coverFileExists(p) {
try { return fs.existsSync(p) && fs.statSync(p).isFile(); } catch { return false; }
} Try / catch
try {
await douyin.publish({ cover });
} catch (e) {
if (e instanceof ArgumentError && /封面文件不存在/.test(e.message)) {
console.error(`Fix --cover path; resolved to: ${e.message}`);
} else throw e;
} Prevention
- Always pass absolute paths for asset files
- Check cwd assumptions in scripts that build relative paths
- Verify generated cover files exist before chaining pipeline steps
- Watch for case-sensitivity when moving between macOS and Linux
When it happens
Trigger: Passing kwargs.cover pointing to a file that does not exist at publish time — wrong relative path (resolved against CWD), file deleted/moved after typing the command, or a typo in the filename/extension.
Common situations: Running the CLI from a different working directory than expected so a relative cover path resolves elsewhere; cover generated by a previous step that failed; shell quoting stripping characters from the path; macOS vs Linux case-sensitive filesystems.
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
- not a regular file: ${abs}
- file is empty: ${abs}
- ${label}文件不存在: ${resolved}
- Not a valid file: ${absPath}
- Not a valid image file: ${absPath}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c9c16831f07c797e.
Report an issue: GitHub.