diff options
author | 2023-10-14 08:51:36 +0800 | |
---|---|---|
committer | 2023-10-13 17:51:36 -0700 | |
commit | d08e112d416ddee7af8d499524e40e7f193ae55a (patch) | |
tree | 8ced72a8d8ff67cbc77afe36bffc5269c3d832c4 | |
parent | 77d7e47019753bacc76306dd9066df25c67c51a9 (diff) | |
download | bun-d08e112d416ddee7af8d499524e40e7f193ae55a.tar.gz bun-d08e112d416ddee7af8d499524e40e7f193ae55a.tar.zst bun-d08e112d416ddee7af8d499524e40e7f193ae55a.zip |
fix(error): correct the `path` field in syscall error message. (#6370)
* fix(error): correct the `path` field in syscall error message.
Close: #6336
* fix pathlike union case
-rw-r--r-- | src/bun.js/webcore/blob.zig | 29 | ||||
-rw-r--r-- | test/js/bun/io/bun-write.test.js | 25 |
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) { |