jackwener/OpenCLI · error · ArgumentError
${label}文件不存在: ${resolved}
Error message
${label}文件不存在: ${resolved} What it means
requireFilePath validates a user-supplied file path before publishing media. It resolves the path absolutely and calls fs.statSync; if the path does not exist (stat throws), it throws an ArgumentError prefixed with the Chinese label (e.g. 视频文件不存在) including the resolved path so the user sees exactly which path was not found.
Source
Thrown at clis/wechat-channels/publish.js:70
function unwrapEvaluateResult(result) {
if (result && typeof result === 'object' && 'data' in result && 'session' in result) {
return result.data;
}
return result;
}
async function evalPage(page, script) {
return unwrapEvaluateResult(await page.evaluate(script));
}
function requireFilePath(filePath, label, allowedExts) {
const resolved = path.resolve(String(filePath));
let stat;
try {
stat = fs.statSync(resolved);
} catch {
throw new ArgumentError(`${label}文件不存在: ${resolved}`);
}
if (!stat.isFile()) {
throw new ArgumentError(`${label}路径不是文件: ${resolved}`);
}
const ext = path.extname(resolved).toLowerCase();
if (!allowedExts.has(ext)) {
throw new ArgumentError(`不支持的${label}格式: ${ext}(支持 ${Array.from(allowedExts).join('/')})`);
}
return resolved;
}
function parseTimeoutSeconds(raw) {
const timeout = raw == null || raw === '' ? 600 : Number(raw);
if (!Number.isInteger(timeout) || timeout < 30) {
throw new ArgumentError('--timeout must be an integer >= 30 seconds');
}
return timeout;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Check the resolved path in the error message and verify the file exists there (ls).
- Use an absolute path to eliminate CWD ambiguity.
- Quote paths containing spaces in the shell.
- Confirm the file was created/uploaded and the volume is mounted (especially in containers).
- Fix case-sensitivity mismatches on Linux filesystems.
Example fix
// before wechat-channels publish --video-path ./my video.mp4 # parsed as two args / wrong CWD // after wechat-channels publish --video-path "/abs/path/to/my video.mp4"
Defensive patterns
Strategy: validation
Validate before calling
import fs from 'node:fs'; import path from 'node:path';
function assertFileExists(p) {
const resolved = path.resolve(String(p));
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) {
throw new Error(`File not found: ${resolved}`);
}
return resolved;
}
// before publishing: assertFileExists(opts.videoPath); Type guard
function isExistingFile(p) {
try { return fs.statSync(path.resolve(String(p))).isFile(); } catch { return false; }
} Try / catch
try {
await publish({ videoPath: videoPath });
} catch (e) {
if (/文件不存在/.test(e.message)) {
console.error(`Path not found: ${e.message}. CWD=${process.cwd()}`);
process.exitCode = 2;
} else throw e;
} Prevention
- Always pass absolute paths; never rely on CWD
- Quote shell arguments containing spaces
- Check file existence (and extension) before invoking publish commands
- Ensure files/volumes are mounted when running in containers
When it happens
Trigger: Passing --video-path (via videoPath) a path that doesn't exist: typo in the filename, wrong working directory for a relative path, file deleted/moved before the call, missing drive/mount, or shell quoting issues dropping part of the path.
Common situations: Relative path resolved from a different CWD than expected; video not yet downloaded/exported; filename case mismatch on case-sensitive filesystems; spaces in filename unquoted in the shell; running the CLI in a container without the host file mounted.
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
- 封面文件不存在: ${path.resolve(coverPath)}
- 封面文件不存在: ${path.resolve(coverPath)}
- Media file not found: ${resolved}
- Story media file not found: ${resolved}
- file not readable: ${abs} (${e.message})
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/c83cd7b21ce48d65.
Report an issue: GitHub.