{"record":{"id":"967fe0d48fa078cd","repo":"jackwener/OpenCLI","slug":"video-file-not-found-filepath","errorCode":null,"errorMessage":"Video file not found: ${filePath}","messagePattern":"Video file not found: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/douyin/_shared/tos-upload.js","lineNumber":269,"sourceCode":"    catch {\n        parsed = null;\n    }\n    if (res.status !== 200 || parsed?.code !== 2000) {\n        throw new CommandExecutionError(`TOS complete multipart upload failed with status ${res.status}: ${res.body}`, 'Check that all parts were uploaded successfully.');\n    }\n    return parsed?.data?.key || null;\n}\nlet _readSyncOverride = null;\n/** @internal — for testing only */\nexport function setReadSyncOverride(fn) {\n    _readSyncOverride = fn;\n}\n// ── Public API ───────────────────────────────────────────────────────────────\nexport async function tosUpload(options) {\n    const { filePath, uploadInfo, credentials, onProgress } = options;\n    // Validate file exists\n    if (!fs.existsSync(filePath)) {\n        throw new CommandExecutionError(`Video file not found: ${filePath}`, 'Ensure the file path is correct and accessible.');\n    }\n    const { size: fileSize } = fs.statSync(filePath);\n    if (fileSize === 0) {\n        throw new CommandExecutionError(`Video file is empty: ${filePath}`);\n    }\n    const { tos_upload_url: tosUrl, auth, upload_header: uploadHeader, user_id: userId } = uploadInfo;\n    const parsedTosUrl = new URL(tosUrl);\n    const region = extractRegionFromHost(parsedTosUrl.host);\n    const resumePath = getResumeFilePath(filePath);\n    let resumeState = loadResumeState(resumePath, fileSize);\n    let uploadId;\n    let completedParts;\n    if (resumeState) {\n        // Resume from previous state\n        uploadId = resumeState.uploadId;\n        completedParts = resumeState.parts;\n    }\n    else {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/_shared/tos-upload.js#L251-L287","documentation":"tosUpload validates that the video file exists before reading it; this CommandExecutionError is thrown when fs.existsSync(filePath) is false. Nothing is uploaded.","triggerScenarios":"Calling tosUpload with a filePath that doesn't exist — typo'd path, relative path resolved from a different cwd, deleted temp file, or wrong path separator.","commonSituations":"Script run from a different working directory than expected; output file from a prior render step missing because that step failed; Windows-style path used on POSIX.","solutions":["Check the path exists with fs.existsSync/path.resolve before calling and fix it","Use absolute paths (path.resolve(__dirname, ...)) instead of relative ones","Verify the pipeline step that produces the video file actually succeeded","Check file permissions and that the path separator matches the OS"],"exampleFix":"// before\nawait tosUpload({ filePath: 'out/video.mp4', ... });\n// after\nconst filePath = path.resolve('out/video.mp4');\nif (!fs.existsSync(filePath)) throw new Error(`missing input: ${filePath}`);\nawait tosUpload({ filePath, ... });","handlingStrategy":"validation","validationCode":"import fs from 'node:fs';\nimport path from 'node:path';\nconst abs = path.resolve(filePath);\nif (!fs.existsSync(abs) || !fs.statSync(abs).isFile()) {\n  throw new Error(`video file missing: ${abs}`);\n}","typeGuard":"function isExistingFile(p) {\n  try { return fs.statSync(p).isFile(); } catch { return false; }\n}","tryCatchPattern":"try { await tosUpload(options); }\ncatch (e) {\n  if (String(e.message).startsWith('Video file not found')) {\n    console.error(`check path: ${options.filePath} (cwd=${process.cwd()})`);\n  }\n  throw e;\n}","preventionTips":["Always pass absolute paths to tosUpload","Assert the producing pipeline step wrote the file before uploading","Log process.cwd() when debugging relative-path issues","Add a preflight existsSync check with a clear error message"],"tags":["filesystem","validation","input"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}