{"record":{"id":"04eb69d6b11466f0","repo":"jackwener/OpenCLI","slug":"label-must-reference-a-non-empty-file-ref-va","errorCode":null,"errorMessage":"${label} must reference a non-empty file: ${ref.value}","messagePattern":"(.+?) must reference a non-empty file: (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/midjourney/utils.js","lineNumber":912,"sourceCode":"      } catch (error) {\n        if (error instanceof ArgumentError) throw error;\n      }\n      return { kind: 'url', value: item };\n    }\n    const expanded = item === '~' ? os.homedir() : item.startsWith('~/') ? path.join(os.homedir(), item.slice(2)) : item;\n    return { kind: 'local', value: path.resolve(expanded) };\n  });\n}\n\nexport async function validateLocalReferences(refs, label) {\n  for (const ref of refs.filter((item) => item.kind === 'local')) {\n    let stat;\n    try {\n      stat = await fs.stat(ref.value);\n    } catch {\n      throw new ArgumentError(`${label} file does not exist: ${ref.value}`);\n    }\n    if (!stat.isFile() || stat.size <= 0) throw new ArgumentError(`${label} must reference a non-empty file: ${ref.value}`);\n    if (stat.size > MAX_REFERENCE_BYTES) throw new ArgumentError(`${label} exceeds Midjourney's 10MB upload limit: ${ref.value}`);\n    const ext = path.extname(ref.value).toLowerCase();\n    if (!IMAGE_EXTENSIONS.has(ext)) throw new ArgumentError(`${label} must be PNG, JPEG, WEBP, or GIF: ${ref.value}`);\n  }\n  return refs;\n}\n\nasync function visibleImageSources(page) {\n  const payload = unwrapEvaluateResult(await page.evaluate(() => [...document.querySelectorAll('img[src]')]\n    .filter((img) => {\n      const rect = img.getBoundingClientRect();\n      let card = img.parentElement;\n      while (card && !String(card.className).includes('group/img')) card = card.parentElement;\n      return Boolean(card) && rect.width > 24 && rect.height > 24 && /cdn\\.midjourney\\.com\\/u\\//.test(img.src);\n    })\n    .map((img) => img.src)));\n  return Array.isArray(payload) ? payload.map(String) : [];\n}","sourceCodeStart":894,"sourceCodeEnd":930,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/midjourney/utils.js#L894-L930","documentation":"After fs.stat succeeds, the validator requires the reference to be a regular file (stat.isFile()) with size > 0. This ArgumentError is thrown for directories, special files (fifos/devices), and zero-byte files, since Midjourney cannot consume empty or non-file uploads.","triggerScenarios":"Passing a directory as a reference, passing a 0-byte file left by a failed download or touch, or passing a fifo/socket/device path.","commonSituations":"An earlier download step failed leaving a 0-byte placeholder, pipelines creating empty output files on error, users passing a folder expecting the tool to pick images from it.","solutions":["Point the reference at an actual image file, not a directory or special file","Check size (ls -l / stat) and re-export/re-download if the file is 0 bytes","Fix the upstream step that produced the empty file"],"exampleFix":"// before\n--refs ./images/               // directory\n--refs ./broken-download.png   // 0 bytes\n// after\n--refs ./images/cat.png        // real, non-empty file","handlingStrategy":"validation","validationCode":"const s = await fs.stat(p);\nif (!s.isFile() || s.size <= 0) throw new Error(`${p} is not a non-empty regular file`);","typeGuard":"const isNonEmptyFile = async (p) => { try { const s = await fs.stat(p); return s.isFile() && s.size > 0; } catch { return false; } };","tryCatchPattern":"try {\n  await validateLocalReferences(refs, 'refs');\n} catch (e) {\n  if (String(e.message).includes('must reference a non-empty file')) {\n    console.error('Re-generate or re-download the file:', e.message);\n  }\n  throw e;\n}","preventionTips":["Never pass directories — point at individual image files","After downloads, assert size > 0 before continuing the pipeline","Treat 0-byte files as failed artifacts and re-produce them"],"tags":["filesystem","argument-validation","empty-file"],"backgroundTag":"file-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}