jackwener/OpenCLI · error · ArgumentError
manifestPath
Error message
manifestPath
What it means
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.
Source
Thrown at clis/grok/export-all.js:41
}
return n;
}
async function waitRandom(page, minMs, maxMs) {
if (maxMs <= 0) return;
const span = Math.max(0, maxMs - minMs);
const ms = minMs + Math.floor(Math.random() * (span + 1));
if (ms > 0) await page.wait(ms / 1000);
}
function readManifest(manifestPath, { offset, limit }) {
const path = String(manifestPath || '').trim();
if (!path) return null;
let parsed;
try {
parsed = JSON.parse(fs.readFileSync(path, 'utf8'));
} catch (error) {
throw new ArgumentError('manifestPath', `failed to read JSON manifest: ${error?.message || error}`);
}
const rows = normalizeManifestRows(parsed);
const sliced = limit ? rows.slice(offset, offset + limit) : rows.slice(offset);
if (!sliced.length) {
throw new EmptyResultError('grok export-all', `No manifest rows after offset=${offset}, limit=${limit}`);
}
return sliced;
}
async function collectHistory(page, { offset, limit, maxScrolls }) {
await page.goto(GROK_URL);
await page.wait(2);
const rawResult = await page.evaluate(`(async () => {
const targetLimit = ${JSON.stringify(limit > 0 ? offset + limit : 0)};
const maxScrolls = ${JSON.stringify(maxScrolls)};
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const isVisible = (node) => {
if (!(node instanceof Element)) return false;View on GitHub (pinned to 49907e53dc)
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
Example fix
// before
cli.exportAll({ manifestPath: './manifst.json' }); // typo
// after
cli.exportAll({ manifestPath: './manifest.json' }); Defensive patterns
Strategy: validation
Validate before calling
const fs = require('fs');
function validateManifest(p) {
const raw = fs.readFileSync(p, 'utf8');
JSON.parse(raw); // throws early with a clearer stack
return p;
} Type guard
function isReadableJsonFile(p) { try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; } catch { return false; } } Try / catch
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; } Prevention
- 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
When it happens
Trigger: clis/grok/export-all.js:41 throws when fs.readFileSync(path,'utf8') or JSON.parse fails for the provided manifest file path.
Common situations: 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.
Related errors
- <train-no> must not be empty
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/d6222a05f4dab53c.
Report an issue: GitHub.