{"record":{"id":"20a20648eb9c5990","repo":"jackwener/OpenCLI","slug":"could-not-store-midjourney-kind-at-filepath","errorCode":null,"errorMessage":"Could not store Midjourney ${kind} at ${filePath}: ${errorMessage(error)}","messagePattern":"Could not store Midjourney (.+?) at (.+?): (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":791,"sourceCode":"  } finally {\n    await handle.close();\n  }\n  if (actualMime !== config.mime) {\n    throw new CommandExecutionError(\n      `Midjourney ${kind} returned invalid media bytes; expected ${config.mime}, detected ${actualMime || 'unknown'}`,\n    );\n  }\n  if (downloaded.mime && downloaded.mime !== actualMime) {\n    log.warn(`Browser Bridge reported ${downloaded.mime} for ${sourcePath}; detected ${actualMime} from file bytes`);\n  }\n  const tempPath = `${filePath}.part-${process.pid}-${Date.now()}`;\n  try {\n    await fs.copyFile(sourcePath, tempPath);\n    await fs.rename(tempPath, filePath);\n    if (sourcePath !== filePath) await fs.unlink(sourcePath).catch(() => {});\n  } catch (error) {\n    await fs.unlink(tempPath).catch(() => {});\n    throw new CommandExecutionError(`Could not store Midjourney ${kind} at ${filePath}: ${errorMessage(error)}`);\n  }\n  return {\n    index,\n    kind,\n    filePath,\n    bytes: sourceStat.size,\n    url: stringOrNull(downloaded.finalUrl ?? downloaded.url),\n    mime: actualMime,\n    cached: false,\n  };\n}\n\nexport function displayPath(filePath) {\n  const home = os.homedir();\n  return filePath.startsWith(home) ? `~${filePath.slice(home.length)}` : filePath;\n}\n\nexport async function recordQuotaSnapshot(account, source = 'unknown') {","sourceCodeStart":773,"sourceCodeEnd":809,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L773-L809","documentation":"A CommandExecutionError raised when moving the downloaded file into place fails — fs.copyFile from the browser's download location to a temp path, fs.rename to the final filePath, or unlinking the original all throw. The temp file is cleaned up before rethrowing so no partial artifacts remain.","triggerScenarios":"fs.copyFile or fs.rename in the try block rejects — e.g. destination directory doesn't exist, permissions deny the copy, source vanished mid-copy, or cross-device rename issues (here copy+rename so mainly EACCES/ENOENT/ENOSPC).","commonSituations":"outputDir was deleted or renamed between creation and storage; read-only or non-writable destination volume; disk full; the browser's temp download was cleaned before the copy; Windows file locking if the browser still holds the file open.","solutions":["Ensure outputDir exists and is writable before the download (the function does mkdir recursive, so check for later deletion or permission changes)","Free disk space if ENOSPC","Check/fix ownership and permissions on outputDir","On Windows, wait for the browser to release the file handle before copying","Inspect errorMessage(error) in the message for the underlying errno (EACCES/ENOENT/ENOSPC) and fix accordingly"],"exampleFix":"// before\nawait downloadRenderedVideo(page, jobId, i, kind, readOnlyDir);\n// after\nawait fs.mkdir(destDir, { recursive: true });\nawait fs.access(destDir, fs.constants.W_OK);\nawait downloadRenderedVideo(page, jobId, i, kind, destDir);","handlingStrategy":"try-catch","validationCode":"await fs.promises.mkdir(destDir, { recursive: true });\nawait fs.promises.access(destDir, fs.constants.W_OK);\nconst free = await checkDiskSpace(path.parse(destDir).root);\nif (free.free < 100 * 1024 * 1024) throw new Error('Less than 100MB free — downloads may fail to store');","typeGuard":null,"tryCatchPattern":"try {\n  await downloadRenderedVideo(page, jobId, i, kind, outDir);\n} catch (err) {\n  if (err.message.includes('Could not store Midjourney')) {\n    if (/ENOSPC/.test(err.message)) console.error('Disk full — free space and retry');\n    if (/EACCES|EPERM/.test(err.message)) console.error(`Fix permissions on ${outDir}`);\n    if (/ENOENT/.test(err.message)) console.error('Destination removed mid-run — recreate outputDir');\n  }\n  throw err;\n}","preventionTips":["Create and permission-check outputDir before starting batch downloads","Monitor free disk space for long-running export jobs","Do not delete or move outputDir while the CLI is running","On Windows, ensure no process locks files in the browser download directory"],"tags":["filesystem","file-copy","permissions","midjourney"],"backgroundTag":"file-write-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}