mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-09 10:49:29 +00:00
fix(aria2): harden per-transfer DNS fallback (issue #35)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import type { DownloadErrorKind } from '../bindings/DownloadErrorKind';
|
||||
|
||||
/**
|
||||
* Keep the renderer's presentation classification aligned with the native
|
||||
* Aria2 boundary. This is intentionally narrow: only Aria2's resolver error
|
||||
* or its distinctive DNS-server wording receives DNS-specific guidance.
|
||||
*/
|
||||
export const classifyDownloadError = (message: unknown): DownloadErrorKind | undefined => {
|
||||
if (typeof message !== 'string') return undefined;
|
||||
const lower = message.toLowerCase();
|
||||
if (
|
||||
lower.includes('aria2 error code 19')
|
||||
|| (
|
||||
lower.includes('name resolution')
|
||||
&& lower.includes('failed')
|
||||
&& lower.includes('could not contact dns')
|
||||
)
|
||||
|| lower.includes('could not contact dns server')
|
||||
) {
|
||||
return 'nameResolution';
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
@@ -50,6 +50,16 @@ describe('download persistence progress snapshots', () => {
|
||||
expect(persisted.totalIsEstimate).toBe(false);
|
||||
});
|
||||
|
||||
it('does not persist live resolver error classification', () => {
|
||||
const sanitized = redactDownloadForPersistence({
|
||||
...item('failed'),
|
||||
lastErrorKind: 'nameResolution',
|
||||
lastResolverFallback: true,
|
||||
});
|
||||
expect(sanitized.lastErrorKind).toBeUndefined();
|
||||
expect(sanitized.lastResolverFallback).toBeUndefined();
|
||||
});
|
||||
|
||||
it.each(['queued', 'staged', 'retrying', 'processing'] as const)(
|
||||
'keeps byte counters for %s snapshots',
|
||||
(status) => {
|
||||
|
||||
@@ -577,5 +577,9 @@ export const redactDownloadForPersistence = (item: DownloadItem): DownloadItem =
|
||||
for (const field of DOWNLOAD_SECRET_FIELDS) {
|
||||
delete copy[field];
|
||||
}
|
||||
// Error classification is derived from the live native state and must not
|
||||
// become a persistence field or influence a new lifecycle after restart.
|
||||
delete copy.lastErrorKind;
|
||||
delete copy.lastResolverFallback;
|
||||
return copy;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user