{"record":{"id":"d6222a05f4dab53c","repo":"jackwener/OpenCLI","slug":"manifestpath","errorCode":null,"errorMessage":"manifestPath","messagePattern":"manifestPath","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/grok/export-all.js","lineNumber":41,"sourceCode":"  }\n  return n;\n}\n\nasync function waitRandom(page, minMs, maxMs) {\n  if (maxMs <= 0) return;\n  const span = Math.max(0, maxMs - minMs);\n  const ms = minMs + Math.floor(Math.random() * (span + 1));\n  if (ms > 0) await page.wait(ms / 1000);\n}\n\nfunction readManifest(manifestPath, { offset, limit }) {\n  const path = String(manifestPath || '').trim();\n  if (!path) return null;\n  let parsed;\n  try {\n    parsed = JSON.parse(fs.readFileSync(path, 'utf8'));\n  } catch (error) {\n    throw new ArgumentError('manifestPath', `failed to read JSON manifest: ${error?.message || error}`);\n  }\n  const rows = normalizeManifestRows(parsed);\n  const sliced = limit ? rows.slice(offset, offset + limit) : rows.slice(offset);\n  if (!sliced.length) {\n    throw new EmptyResultError('grok export-all', `No manifest rows after offset=${offset}, limit=${limit}`);\n  }\n  return sliced;\n}\n\nasync function collectHistory(page, { offset, limit, maxScrolls }) {\n  await page.goto(GROK_URL);\n  await page.wait(2);\n  const rawResult = await page.evaluate(`(async () => {\n    const targetLimit = ${JSON.stringify(limit > 0 ? offset + limit : 0)};\n    const maxScrolls = ${JSON.stringify(maxScrolls)};\n    const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));\n    const isVisible = (node) => {\n      if (!(node instanceof Element)) return false;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/grok/export-all.js#L23-L59","documentation":"ArgumentError('manifestPath') thrown by readManifest when the file given via manifestPath cannot be read or parsed as JSON. Any fs.readFileSync or JSON.parse failure (missing file, permissions, invalid JSON) is wrapped into this error with the underlying message appended.","triggerScenarios":"clis/grok/export-all.js:41 throws when fs.readFileSync(path,'utf8') or JSON.parse fails for the provided manifest file path.","commonSituations":"Typo in manifest file path; file moved/deleted between runs; manifest written with a trailing error message or truncated JSON; passing a directory or an HTML error page saved as .json; permission denied.","solutions":["Verify the manifestPath points to an existing readable file (ls/cat it)","Validate the file parses: node -e 'JSON.parse(require(\"fs\").readFileSync(\"manifest.json\",\"utf8\"))'","Re-export/regenerate the manifest if it is truncated or corrupted","Check file permissions and that the path is relative to the correct working directory"],"exampleFix":"// before\ncli.exportAll({ manifestPath: './manifst.json' }); // typo\n// after\ncli.exportAll({ manifestPath: './manifest.json' });","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction validateManifest(p) {\n  const raw = fs.readFileSync(p, 'utf8');\n  JSON.parse(raw); // throws early with a clearer stack\n  return p;\n}","typeGuard":"function isReadableJsonFile(p) { try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; } catch { return false; } }","tryCatchPattern":"try { await cli.exportAll({ manifestPath }); } catch (e) { if (e.name === 'ArgumentError' && e.message.includes('manifestPath')) { console.error('Manifest unreadable/invalid JSON:', e.message); } else throw e; }","preventionTips":["fs.existsSync + JSON.parse sanity check before invoking","Regenerate the manifest after interrupted exports","Use absolute paths to avoid cwd mismatch","Verify file permissions for the running user"],"tags":["file-io","json-parse","argument-validation"],"backgroundTag":"invalid-json-file","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}