fix(document): localize loadDocument error too — no raw pdf.js text

The render path was localized but loadDocument still stored the raw
pdf.js message (and an untranslated English fallback), contradicting the
"never leak raw error text" principle. Both load and render failures now
set the localized doc_render_failed message.

Addresses re-review: Felix, Nora (raw error leak on the load path).

Refs #708

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-01 20:42:30 +02:00
committed by marcel
parent 4c57a2262f
commit f24c415b04
2 changed files with 7 additions and 4 deletions

View File

@@ -277,7 +277,7 @@ describe('createPdfRenderer', () => {
expect(r.error).toBeNull(); expect(r.error).toBeNull();
}); });
it('loadDocument sets error and loading=false when getDocument().promise rejects', async () => { it('loadDocument sets a localized error (not the raw pdf.js message) when getDocument rejects', async () => {
const failingLib = { const failingLib = {
GlobalWorkerOptions: { workerSrc: '' }, GlobalWorkerOptions: { workerSrc: '' },
getDocument: vi.fn().mockReturnValue({ getDocument: vi.fn().mockReturnValue({
@@ -294,6 +294,7 @@ describe('createPdfRenderer', () => {
await r.init(); await r.init();
await r.loadDocument('/bad/path'); await r.loadDocument('/bad/path');
expect(r.loading).toBe(false); expect(r.loading).toBe(false);
expect(r.error).toBe('PDF not found'); expect(r.error).toBe(m.doc_render_failed());
expect(r.error).not.toContain('PDF not found');
}); });
}); });

View File

@@ -55,8 +55,10 @@ export function createPdfRenderer(libLoader: LibLoader = defaultLibLoader) {
const doc = await loadingTask.promise; const doc = await loadingTask.promise;
pdfDoc = doc; pdfDoc = doc;
totalPages = doc.numPages; totalPages = doc.numPages;
} catch (e) { } catch {
error = e instanceof Error ? e.message : 'Failed to load PDF'; // Never surface the raw pdf.js message — show a localized failure
// that routes into the viewer's error UI (message + download link).
error = m.doc_render_failed();
} finally { } finally {
loading = false; loading = false;
} }