{"record":{"id":"dae704701e7e608b","repo":"jackwener/OpenCLI","slug":"midjourney-kind-download-did-not-complete-do","errorCode":null,"errorMessage":"Midjourney ${kind} download did not complete: ${downloaded?.error || downloaded?.state || 'unknown'}","messagePattern":"Midjourney (.+?) download did not complete: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":760,"sourceCode":"  await page.wait({ selector: 'video[src]', timeout: 20 });\n  await page.click('button[title=\"Options\"]');\n  await page.wait(0.3);\n  const marked = unwrapEvaluateResult(await page.evaluate((label) => {\n    document.querySelectorAll('[data-opencli-video-download]').forEach((node) => node.removeAttribute('data-opencli-video-download'));\n    const button = [...document.querySelectorAll('button[role=\"menuitem\"],button')]\n      .find((node) => node.textContent?.trim() === label && node.getBoundingClientRect().width > 0);\n    if (!button) return false;\n    button.setAttribute('data-opencli-video-download', '1');\n    return true;\n  }, config.label));\n  if (!marked) throw new CommandExecutionError(`Midjourney did not expose \"${config.label}\" for video ${jobId}`);\n  await page.click('[data-opencli-video-download=\"1\"]');\n  if (typeof page.waitForDownload !== 'function') {\n    throw new CommandExecutionError('Browser Bridge download lifecycle support is required for social video/GIF export');\n  }\n  const downloaded = await page.waitForDownload(jobId, 60_000);\n  if (!downloaded?.downloaded || downloaded.state !== 'complete' || !downloaded.filename) {\n    throw new CommandExecutionError(`Midjourney ${kind} download did not complete: ${downloaded?.error || downloaded?.state || 'unknown'}`);\n  }\n  const sourcePath = path.resolve(String(downloaded.filename));\n  const sourceStat = await fs.stat(sourcePath).catch(() => null);\n  if (!sourceStat?.isFile() || sourceStat.size <= 0) {\n    throw new CommandExecutionError(`Browser reported a completed download but the file is missing: ${sourcePath}`);\n  }\n  const handle = await fs.open(sourcePath, 'r');\n  let actualMime;\n  try {\n    const header = Buffer.alloc(16);\n    const { bytesRead } = await handle.read(header, 0, header.length, 0);\n    actualMime = sniffMediaMime(header.subarray(0, bytesRead));\n  } 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'}`,","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L742-L778","documentation":"A CommandExecutionError thrown when page.waitForDownload resolves but the result is not a successful complete download — either downloaded.downloaded is falsy, state is not 'complete', or no filename was reported. The message interpolates the bridge's error field or state so you can see why the download failed.","triggerScenarios":"The 60-second waitForDownload window expires (state 'timeout'), the browser cancels or fails the download (state 'failed'/'cancelled'), or the bridge returns an error string in downloaded.error.","commonSituations":"Large GIF/social renders exceeding 60s on slow connections; Midjourney auth expiring mid-download so the click triggers a login page instead; user closing the browser tab during download; disk-full or permission-denied in the browser's download directory.","solutions":["Increase the 60_000ms timeout for large/slow downloads","Re-authenticate the Midjourney browser session and retry","Check free disk space and write permissions on the browser's download directory","Inspect the interpolated state/error in the message to target the specific failure (timeout vs failed)","Retry the command — transient CDN slowness commonly causes timeouts"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":"function isCompletedDownload(d) {\n  return Boolean(d && d.downloaded && d.state === 'complete' && d.filename);\n}","tryCatchPattern":"try {\n  await downloadRenderedVideo(page, jobId, i, kind, outDir);\n} catch (err) {\n  if (err.message.includes('download did not complete')) {\n    log.warn(`Download incomplete (${err.message}), retrying...`);\n    await downloadRenderedVideo(page, jobId, i, kind, outDir, true);\n  } else throw err;\n}","preventionTips":["Ensure the Midjourney session is freshly authenticated before long export runs","Free disk space and verify write access to the browser's download directory beforehand","Keep the browser window/tab open for the duration of the download","Allow extra wall-clock time for large GIF renders; avoid parallel downloads saturating bandwidth"],"tags":["download-failed","midjourney","browser-automation","timeout"],"backgroundTag":"download-incomplete","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}