fix: a save that fails falls back to a new file only for a lost handle

Any error but an encryption one went to Save As, which hid exporter bugs
and silently turned a .docx document into .odt. Only a handle that lost
its permission or its file prompts again now, in the document's format.
This commit is contained in:
Steffen Becker committed 2026-09-04 19:30:12 +02:00
1 parent 137fce047a
commit b2cb216af0
1 file changed
+4 -3
+4 -3
View File
@@ -880,9 +880,10 @@
recentFiles = await rememberRecentFile(fileHandle?.name ?? suggestedFilename(json), fileHandle);
} catch (err) {
if ((err as DOMException)?.name === 'AbortError') return;
// A stored handle may have lost permission; re-prompt via Save As. Encryption
// failing is not that case — it would silently save the document unprotected.
if (fileHandle && (err as Error)?.name !== 'EncryptionError') { fileHandle = null; await handleSaveAs(); return; }
// A stored handle may have lost its permission or its file: prompt for a new one,
// in the document's own format. Every other error is reported, not papered over.
const name = (err as DOMException)?.name;
if (fileHandle && (name === 'NotAllowedError' || name === 'NotFoundError')) { fileHandle = null; return handleSave(); }
console.error('[save] Failed to save file:', err);
failed(t().dialogs.couldNotSave, err);
}