jackwener/OpenCLI · error · CommandExecutionError
Could not parse Twitter likes resume file ${filePath}: ${err
Error message
Could not parse Twitter likes resume file ${filePath}: ${error instanceof Error ? error.message : String(error)} What it means
readResumeFile in the twitter likes CLI throws this CommandExecutionError when the resume file exists but its contents are not valid JSON (fs.readFileSync succeeded, JSON.parse failed). The error includes the file path and the underlying parse message so the developer knows which artifact is corrupt.
Source
Thrown at clis/twitter/likes.js:128
}
for (const item of content?.items || []) {
const nested = extractLikedTweet(item.item?.itemContent?.tweet_results?.result, seen);
if (nested)
tweets.push(nested);
}
}
}
return { tweets, nextCursor };
}
function readResumeFile(filePath, expected = null) {
if (!filePath || !fs.existsSync(filePath))
return null;
let parsed;
try {
parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
}
catch (error) {
throw new CommandExecutionError(`Could not parse Twitter likes resume file ${filePath}: ${error instanceof Error ? error.message : String(error)}`);
}
const count = parsed?.count;
const cursor = parsed?.cursor == null ? null : String(parsed.cursor);
const outputFile = parsed?.outputFile ? path.resolve(String(parsed.outputFile)) : null;
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)
|| !Number.isInteger(count) || count < 0
|| (parsed.cursor != null && typeof parsed.cursor !== 'string')
|| (cursor !== null && !cursor.trim())) {
throw new CommandExecutionError(`Twitter likes resume file ${filePath} has an invalid shape`);
}
if (expected) {
if (parsed.source !== expected.source)
throw new ArgumentError(`Resume file source mismatch: expected ${expected.source}, found ${parsed.source || 'unknown'}`);
if (String(parsed.username || '').toLowerCase() !== String(expected.username).toLowerCase())
throw new ArgumentError(`Resume file username mismatch: expected @${expected.username}, found @${parsed.username || 'unknown'}`);
if (outputFile !== expected.outputFile)
throw new ArgumentError(`Resume file output mismatch: expected ${expected.outputFile || 'in-memory mode'}, found ${outputFile || 'in-memory mode'}`);
if (!expected.outputFile && !Array.isArray(parsed.tweets))View on GitHub (pinned to 49907e53dc)
Solutions
- Inspect the file at filePath and fix the JSON syntax (validate with a JSON linter)
- Delete the corrupt resume file and restart the likes run from scratch
- Re-create the resume file from a known-good backup
- Ensure the process writing the resume file completes atomically (write to temp then rename) in your wrapper
Example fix
// before (truncated/corrupt resume.json)
{"count": 42, "cursor": "abc
// after
{"count": 42, "cursor": "abc", "source": "likes", "username": "someuser"} Defensive patterns
Strategy: validation
Validate before calling
function canParseResumeFile(filePath) {
try { JSON.parse(fs.readFileSync(filePath, 'utf8')); return true; }
catch { return false; }
}
// resume only if canParseResumeFile(resumePath) Try / catch
try {
await runLikes({ resume: resumePath });
} catch (e) {
if (/Could not parse Twitter likes resume file/.test(e.message)) {
fs.rmSync(resumePath); // or restore a backup, then restart fresh
return runLikes({});
}
throw e;
} Prevention
- Validate resume files with a JSON parser before passing --resume
- Write resume files atomically (temp file + rename) if wrapping the CLI
- Don't hand-edit resume files; let the library generate them
- Keep backups of resume files before long runs
When it happens
Trigger: Calling the `twitter likes` command in resume mode (e.g. `--resume <file>`) where the file at filePath exists but contains malformed JSON — truncated writes, manual edits, empty file, or non-JSON content.
Common situations: A previous run was killed mid-write leaving a truncated resume file; the file was edited by hand with trailing commas/comments; the file was overwritten by another tool; resuming against a file from a different format/version of the library.
Related errors
- Twitter likes resume file ${filePath} has an invalid shape
- Twitter likes resume file ${filePath} is missing in-memory t
- Bilibili conclusion API returned malformed model_result JSON
- ${label} must be a path/URL or a JSON array: ${errorMessage(
- Could not parse Twitter bookmarks resume file ${filePath}: $
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/212121966fc2aacf.
Report an issue: GitHub.