From d4237b07574f54b8ac51a3ab4790376f91bd2f10 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 15 Aug 2024 23:19:25 -0700 Subject: [PATCH] node:fs: mode+flags message cleanup (#13332) --- src/bun.js/node/types.zig | 4 ++-- test/js/node/fs/fs.test.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index a2b392b38e601d..d78a0f8b7c5371 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1134,7 +1134,7 @@ pub fn timeLikeFromJS(globalObject: *JSC.JSGlobalObject, value: JSC.JSValue, _: pub fn modeFromJS(ctx: JSC.C.JSContextRef, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?Mode { const mode_int = if (value.isNumber()) brk: { if (!value.isUInt32AsAnyInt()) { - exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"mode\" is out of range. It must be an integer. Received {d}", .{value.toUInt64NoTruncate()}).toJS().asObjectRef(); + exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"mode\" is out of range. It must be an integer. Received {d}", .{value.asNumber()}).toJS().asObjectRef(); return null; } break :brk @as(Mode, @truncate(value.to(Mode))); @@ -1340,7 +1340,7 @@ pub const FileSystemFlags = enum(Mode) { pub fn fromJS(ctx: JSC.C.JSContextRef, val: JSC.JSValue, exception: JSC.C.ExceptionRef) ?FileSystemFlags { if (val.isNumber()) { if (!val.isInt32()) { - exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.toInt64()}).toJS().asObjectRef(); + exception.* = ctx.ERR_OUT_OF_RANGE("The value of \"flags\" is out of range. It must be an integer. Received {d}", .{val.asNumber()}).toJS().asObjectRef(); return null; } const number = val.coerce(i32, ctx); diff --git a/test/js/node/fs/fs.test.ts b/test/js/node/fs/fs.test.ts index cbf10a78904ffd..c1f7f1d0214a1c 100644 --- a/test/js/node/fs/fs.test.ts +++ b/test/js/node/fs/fs.test.ts @@ -3296,6 +3296,10 @@ it("open flags verification", async () => { expect(() => fs.open(__filename, invalid, () => {})).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE"); expect(() => fs.openSync(__filename, invalid)).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE"); expect(async () => await fs.promises.open(__filename, invalid)).toThrow(RangeError); + + expect(() => fs.open(__filename, 4294967298.5, () => {})).toThrow( + RangeError(`The value of "flags" is out of range. It must be an integer. Received 4294967298.5`), + ); }); it("open mode verification", async () => { @@ -3303,4 +3307,8 @@ it("open mode verification", async () => { expect(() => fs.open(__filename, 0, invalid, () => {})).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE"); expect(() => fs.openSync(__filename, 0, invalid)).toThrowWithCode(RangeError, "ERR_OUT_OF_RANGE"); expect(async () => await fs.promises.open(__filename, 0, invalid)).toThrow(RangeError); + + expect(() => fs.open(__filename, 0, 4294967298.5, () => {})).toThrow( + RangeError(`The value of "mode" is out of range. It must be an integer. Received 4294967298.5`), + ); });