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:
@@ -43,8 +43,7 @@ async function info(id, novelPath) {
|
|||||||
infoRunning++;
|
infoRunning++;
|
||||||
try {
|
try {
|
||||||
const { code, out, err } = await run('novel-info.js', [id, novelPath]);
|
const { code, out, err } = await run('novel-info.js', [id, novelPath]);
|
||||||
if (code !== 0)
|
if (code !== 0) throw new Error(errorLine(err, code));
|
||||||
throw new Error(err.trim().split('\n').pop() || `exit ${code}`);
|
|
||||||
const result = JSON.parse(out.trim().split('\n').pop());
|
const result = JSON.parse(out.trim().split('\n').pop());
|
||||||
infos.set(cacheKey, { at: Date.now(), info: result });
|
infos.set(cacheKey, { at: Date.now(), info: result });
|
||||||
return 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();
|
const safeName = s => s.replace(/[/\\:*?"<>|]/g, '-').trim();
|
||||||
|
|
||||||
// One folder per series, named after the book: Kavita groups by folder.
|
// 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();
|
const file = out.trim().split('\n').pop();
|
||||||
if (code !== 0 || !file || !fs.existsSync(file)) {
|
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.progress = err.trim().split('\n')[0] || '';
|
||||||
job.title = place(file);
|
job.title = place(file);
|
||||||
@@ -171,8 +178,7 @@ http
|
|||||||
if (hit && Date.now() - hit.at < FIND_TTL_MS)
|
if (hit && Date.now() - hit.at < FIND_TTL_MS)
|
||||||
return send(res, 200, hit.results);
|
return send(res, 200, hit.results);
|
||||||
const { code, out, err } = await run('find-novel.js', ['--json', q]);
|
const { code, out, err } = await run('find-novel.js', ['--json', q]);
|
||||||
if (code !== 0)
|
if (code !== 0) return send(res, 502, { error: errorLine(err, code) });
|
||||||
return send(res, 502, { error: err.trim().split('\n').pop() });
|
|
||||||
const results = JSON.parse(out.trim().split('\n').pop() || '[]');
|
const results = JSON.parse(out.trim().split('\n').pop() || '[]');
|
||||||
found.set(q.toLowerCase(), { at: Date.now(), results });
|
found.set(q.toLowerCase(), { at: Date.now(), results });
|
||||||
return send(res, 200, results);
|
return send(res, 200, results);
|
||||||
|
|||||||
Reference in New Issue
Block a user