{"record":{"id":"c83cd7b21ce48d65","repo":"jackwener/OpenCLI","slug":"label-resolved","errorCode":null,"errorMessage":"${label}文件不存在: ${resolved}","messagePattern":"(.+?)文件不存在: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/wechat-channels/publish.js","lineNumber":70,"sourceCode":"\nfunction unwrapEvaluateResult(result) {\n  if (result && typeof result === 'object' && 'data' in result && 'session' in result) {\n    return result.data;\n  }\n  return result;\n}\n\nasync function evalPage(page, script) {\n  return unwrapEvaluateResult(await page.evaluate(script));\n}\n\nfunction requireFilePath(filePath, label, allowedExts) {\n  const resolved = path.resolve(String(filePath));\n  let stat;\n  try {\n    stat = fs.statSync(resolved);\n  } catch {\n    throw new ArgumentError(`${label}文件不存在: ${resolved}`);\n  }\n  if (!stat.isFile()) {\n    throw new ArgumentError(`${label}路径不是文件: ${resolved}`);\n  }\n  const ext = path.extname(resolved).toLowerCase();\n  if (!allowedExts.has(ext)) {\n    throw new ArgumentError(`不支持的${label}格式: ${ext}（支持 ${Array.from(allowedExts).join('/')}）`);\n  }\n  return resolved;\n}\n\nfunction parseTimeoutSeconds(raw) {\n  const timeout = raw == null || raw === '' ? 600 : Number(raw);\n  if (!Number.isInteger(timeout) || timeout < 30) {\n    throw new ArgumentError('--timeout must be an integer >= 30 seconds');\n  }\n  return timeout;\n}","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wechat-channels/publish.js#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nwechat-channels publish --video-path ./my video.mp4   # parsed as two args / wrong CWD\n// after\nwechat-channels publish --video-path \"/abs/path/to/my video.mp4\"","handlingStrategy":"validation","validationCode":"import fs from 'node:fs'; import path from 'node:path';\nfunction assertFileExists(p) {\n  const resolved = path.resolve(String(p));\n  if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile()) {\n    throw new Error(`File not found: ${resolved}`);\n  }\n  return resolved;\n}\n// before publishing: assertFileExists(opts.videoPath);","typeGuard":"function isExistingFile(p) {\n  try { return fs.statSync(path.resolve(String(p))).isFile(); } catch { return false; }\n}","tryCatchPattern":"try {\n  await publish({ videoPath: videoPath });\n} catch (e) {\n  if (/文件不存在/.test(e.message)) {\n    console.error(`Path not found: ${e.message}. CWD=${process.cwd()}`);\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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"],"tags":["filesystem","validation","argument-error","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}