fix(scripts): report the real error line for failed searches, details and downloads

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
masi
2026-09-26 16:01:18 -03:00
parent fed827e8a3
commit cbb0f7db9c
+11 -5
View File
@@ -43,8 +43,7 @@ async function info(id, novelPath) {
infoRunning++;
try {
const { code, out, err } = await run('novel-info.js', [id, novelPath]);
if (code !== 0)
throw new Error(err.trim().split('\n').pop() || `exit ${code}`);
if (code !== 0) throw new Error(errorLine(err, code));
const result = JSON.parse(out.trim().split('\n').pop());
infos.set(cacheKey, { at: Date.now(), info: result });
return result;
@@ -72,6 +71,14 @@ function run(script, args) {
});
}
// Node ends a crash with its version line; report the line that names the error.
function errorLine(err, code) {
const lines = err.trim().split('\n').filter(Boolean);
return (lines.findLast(l => /error/i.test(l)) || lines[0] || `exit ${code}`)
.trim()
.slice(0, 200);
}
const safeName = s => s.replace(/[/\\:*?"<>|]/g, '-').trim();
// One folder per series, named after the book: Kavita groups by folder.
@@ -101,7 +108,7 @@ async function work() {
]);
const file = out.trim().split('\n').pop();
if (code !== 0 || !file || !fs.existsSync(file)) {
throw new Error(err.trim().split('\n').pop() || `exit ${code}`);
throw new Error(errorLine(err, code));
}
job.progress = err.trim().split('\n')[0] || '';
job.title = place(file);
@@ -171,8 +178,7 @@ http
if (hit && Date.now() - hit.at < FIND_TTL_MS)
return send(res, 200, hit.results);
const { code, out, err } = await run('find-novel.js', ['--json', q]);
if (code !== 0)
return send(res, 502, { error: err.trim().split('\n').pop() });
if (code !== 0) return send(res, 502, { error: errorLine(err, code) });
const results = JSON.parse(out.trim().split('\n').pop() || '[]');
found.set(q.toLowerCase(), { at: Date.now(), results });
return send(res, 200, results);