aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/webcore/blob.zig29
-rw-r--r--test/js/bun/io/bun-write.test.js25
2 files changed, 48 insertions, 6 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index 1e0720ea6..f9699cffc 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -1040,7 +1040,10 @@ pub const Blob = struct {
break :brk result;
},
.err => |err| {
- return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ return JSC.JSPromise.rejectedPromiseValue(
+ globalThis,
+ err.withPath(pathlike.path.slice()).toJSC(globalThis),
+ );
},
}
unreachable;
@@ -1080,8 +1083,13 @@ pub const Blob = struct {
needs_async.* = true;
return .zero;
}
-
- return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ if (comptime !needs_open) {
+ return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ }
+ return JSC.JSPromise.rejectedPromiseValue(
+ globalThis,
+ err.withPath(pathlike.path.slice()).toJSC(globalThis),
+ );
},
}
}
@@ -1110,7 +1118,10 @@ pub const Blob = struct {
break :brk result;
},
.err => |err| {
- return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ return JSC.JSPromise.rejectedPromiseValue(
+ globalThis,
+ err.withPath(pathlike.path.slice()).toJSC(globalThis),
+ );
},
}
unreachable;
@@ -1145,7 +1156,13 @@ pub const Blob = struct {
needs_async.* = true;
return .zero;
}
- return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ if (comptime !needs_open) {
+ return JSC.JSPromise.rejectedPromiseValue(globalThis, err.toJSC(globalThis));
+ }
+ return JSC.JSPromise.rejectedPromiseValue(
+ globalThis,
+ err.withPath(pathlike.path.slice()).toJSC(globalThis),
+ );
},
}
}
@@ -2289,7 +2306,7 @@ pub const Blob = struct {
this.source_fd = 0;
}
- this.system_error = errno.toSystemError();
+ this.system_error = errno.withPath(this.destination_file_store.pathlike.path.slice()).toSystemError();
return AsyncIO.asError(errno.errno);
},
};
diff --git a/test/js/bun/io/bun-write.test.js b/test/js/bun/io/bun-write.test.js
index a05fa283a..fbcc99b66 100644
--- a/test/js/bun/io/bun-write.test.js
+++ b/test/js/bun/io/bun-write.test.js
@@ -80,6 +80,31 @@ it("Bun.file not found returns ENOENT", async () => {
await gcTick();
});
+it("Bun.write file not found returns ENOENT, issue#6336", async () => {
+ const dst = Bun.file(path.join(tmpdir(), "does/not/exist.txt"));
+ try {
+ await gcTick();
+ await Bun.write(dst, "");
+ await gcTick();
+ } catch (exception) {
+ expect(exception.code).toBe("ENOENT");
+ expect(exception.path).toBe(dst.name);
+ }
+
+ const src = Bun.file(path.join(tmpdir(), `test-bun-write-${Date.now()}.txt`));
+ await Bun.write(src, "");
+ try {
+ await gcTick();
+ await Bun.write(dst, src);
+ await gcTick();
+ } catch (exception) {
+ expect(exception.code).toBe("ENOENT");
+ expect(exception.path).toBe(dst.name);
+ } finally {
+ fs.unlinkSync(src.name);
+ }
+});
+
it("Bun.write('out.txt', 'string')", async () => {
for (let erase of [true, false]) {
if (erase) {