Skip to content

Potential double-throw when writable.close() is called after abort(). #48

@AStevensTaylor

Description

@AStevensTaylor

⚠️ Potential issue | 🟡 Minor

Potential double-throw when writable.close() is called after abort().

If writable.write(data) throws, the code calls writable.abort() and then finally calls writable.close(). According to the File System Access API, calling close() on an already-aborted stream will throw. This could mask the original error.

🔧 Proposed fix to avoid close after abort
 	const writable = await fileHandle.createWritable();
+	let aborted = false;
 
 	try {
 		await writable.write(data);
+		await writable.close();
 	} catch (error) {
 		try {
 			await writable.abort();
+			aborted = true;
 		} catch {
 			// Ignore abort errors
 		}
 		throw error;
-	} finally {
-		await writable.close();
 	}
🤖 Prompt for AI Agents
In `@src/lib/fileSystem.ts` around lines 320 - 331, The current try/catch/finally
around writable.write(data) can cause a second error when finally calls
writable.close() after writable.abort(), masking the original write error;
modify the block to track whether abort() was called (e.g., set a local boolean
aborted = true inside the catch before calling await writable.abort()) and in
the finally only call await writable.close() if aborted is false, ensuring
abort() errors remain ignored and the original write error is rethrown;
reference the writable.write, writable.abort, and writable.close calls when
making the change.

Originally posted by @coderabbitai[bot] in #44 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions