Bug
Both openrouter-models/scripts/lib.ts and openrouter-images/scripts/lib.ts call res.json() without any error handling:
// models/lib.ts
return res.json(); // throws SyntaxError on malformed response, unhandled rejection on network failure
// images/lib.ts — postChatCompletion
return res.json(); // same
Additionally, saveImage() and readImageAsDataUrl() in images/lib.ts use raw filesystem operations with no try/catch — a missing input file or unwritable output directory produces a stack trace instead of a user-facing error message.
Impact
Transient network issues, rate limit responses with non-JSON bodies, or bad file paths all produce unhandled Node.js crashes with stack traces. Agents see noise instead of an actionable error.
Fix
Wrap res.json() in a try/catch and emit a clean error:
let json: any;
try {
json = await res.json();
} catch {
console.error(`Error: Could not parse API response (status ${res.status})`);
process.exit(1);
}
Wrap filesystem calls similarly in images/lib.ts.
Reviewed by Perry
Bug
Both
openrouter-models/scripts/lib.tsandopenrouter-images/scripts/lib.tscallres.json()without any error handling:Additionally,
saveImage()andreadImageAsDataUrl()in images/lib.ts use raw filesystem operations with no try/catch — a missing input file or unwritable output directory produces a stack trace instead of a user-facing error message.Impact
Transient network issues, rate limit responses with non-JSON bodies, or bad file paths all produce unhandled Node.js crashes with stack traces. Agents see noise instead of an actionable error.
Fix
Wrap
res.json()in a try/catch and emit a clean error:Wrap filesystem calls similarly in images/lib.ts.
Reviewed by Perry