fix(aria2): harden per-transfer DNS fallback (issue #35)

This commit is contained in:
NimBold
2026-08-05 19:28:56 +03:30
parent 4a83ac97c7
commit c1202229ac
27 changed files with 864 additions and 27 deletions
+23
View File
@@ -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;
};
+10
View File
@@ -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) => {
+4
View File
@@ -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;
};