Spots: a corrupt NZB is a result, not a reason to read the listing again
Test and deploy / test (push) Successful in 59s
Test and deploy / deploy (push) Successful in 1m29s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-08 15:23:24 +02:00
1 parent ee898be8c8
commit 1520a8dc35
2 files changed
+32 -8

No files matched your search

+19 -5
View File
@@ -31,6 +31,9 @@ const MAX_IMAGE_SEGMENTS = 10
/** A claimed spot whose worker died is taken again after this long. */
const RECLAIM_AFTER = '1 hour'
/** The NZB's articles were read, but they don't decode to an NZB (e.g. "invalid code lengths set"). */
export class NzbUnreadable extends Error {}
/**
* A spot's title: from its XML, which is decoded properly (the Subject of a
* raw header is read as ISO-8859-1), else from the header.
@@ -333,10 +336,17 @@ class SpotService {
try {
nzbXml = await this.readNzb(head)
} catch (error: any) {
if (!/^4\d\d/.test(String(error.message))) throw error
// The NZB's articles are gone: the listing can't be downloaded any more.
update.error = 'NZB articles gone'
outcome = 'nzb-gone'
if (error instanceof NzbUnreadable) {
// Corrupt: reading it again won't help (LOG.md 2026-10-08 (12)).
update.error = `NZB unreadable: ${error.message}`.slice(0, 500)
outcome = 'nzb-unreadable'
} else if (/^4\d\d/.test(String(error.message))) {
// The NZB's articles are gone: the listing can't be downloaded any more.
update.error = 'NZB articles gone'
outcome = 'nzb-gone'
} else {
throw error
}
}
const nzb = nzbXml ? parseNzb(nzbXml) : null
if (nzb && nzb.files.length > 0 && isDummyNzb(nzb, head.header.size)) {
@@ -405,7 +415,11 @@ class SpotService {
if (segments.length === 0 || segments.length > MAX_NZB_SEGMENTS) return null
const bodies = []
for (const id of segments) bodies.push(await this.fetch(`BODY <${id.replace(/^<|>$/g, '')}>`))
return decodeSpotBinary(bodies).toString('utf8')
try {
return decodeSpotBinary(bodies).toString('utf8')
} catch (error: any) {
throw new NzbUnreadable(String(error.message))
}
}
/** Downloads the spot's compressed NZB and imports it as a release (D26). */