Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
paperclover committed Jan 11, 2025
1 parent bd32776 commit 1970450
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/sys.zig
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ pub const Error = struct {
var label: ?[]const u8 = null;
if (this.getErrorCodeTagName()) |resolved_errno| {
code, const system_errno = resolved_errno;
err.code = bun.String.static(code.?);
label = libuv_error_map.get(system_errno);
}

Expand Down
27 changes: 15 additions & 12 deletions test/js/bun/util/inspect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ it("TypedArray prints", () => {
expect(input).toBe(`${TypedArray.name}(${buffer.length}) [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]`);
for (let i = 1; i < buffer.length + 1; i++) {
expect(Bun.inspect(buffer.subarray(i))).toBe(
`${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
buffer.length - i === 0
? `${TypedArray.name}(${buffer.length - i}) []`
: `${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
);
}
}
Expand All @@ -239,9 +241,11 @@ it("BigIntArray", () => {
expect(input).toBe(`${TypedArray.name}(${buffer.length}) [ 1n, 2n, 3n, 4n, 5n, 6n, 7n, 8n, 9n, 10n ]`);
for (let i = 1; i < buffer.length + 1; i++) {
expect(Bun.inspect(buffer.subarray(i))).toBe(
`${TypedArray.name}(${buffer.length - i}) [ ` +
[...buffer.subarray(i)].map(a => a.toString(10) + "n").join(", ") +
" ]",
buffer.length - i === 0
? `${TypedArray.name}(${buffer.length - i}) []`
: `${TypedArray.name}(${buffer.length - i}) [ ` +
[...buffer.subarray(i)].map(a => a.toString(10) + "n").join(", ") +
" ]",
);
}
}
Expand All @@ -255,7 +259,9 @@ for (let TypedArray of [Float32Array, Float64Array]) {
expect(input).toBe(`${TypedArray.name}(${buffer.length}) [ ${[Math.fround(42.68)].join(", ")} ]`);
for (let i = 1; i < buffer.length + 1; i++) {
expect(Bun.inspect(buffer.subarray(i))).toBe(
`${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
buffer.length - i === 0
? `${TypedArray.name}(${buffer.length - i}) []`
: `${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
);
}
});
Expand All @@ -269,7 +275,9 @@ for (let TypedArray of [Float32Array, Float64Array]) {
);
for (let i = 1; i < buffer.length + 1; i++) {
expect(Bun.inspect(buffer.subarray(i))).toBe(
`${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
buffer.length - i === 0
? `${TypedArray.name}(${buffer.length - i}) []`
: `${TypedArray.name}(${buffer.length - i}) [ ` + [...buffer.subarray(i)].join(", ") + " ]",
);
}
});
Expand Down Expand Up @@ -553,12 +561,7 @@ describe("console.logging class displays names and extends", async () => {
class A {}
const cases = [A, class B extends A {}, class extends A {}, class {}];

const expected_logs = [
"[class A]",
"[class B extends A]",
"[class (anonymous) extends A]",
"[class (anonymous)]",
];
const expected_logs = ["[class A]", "[class B extends A]", "[class (anonymous) extends A]", "[class (anonymous)]"];

for (let i = 0; i < cases.length; i++) {
it(expected_logs[i], () => {
Expand Down
4 changes: 2 additions & 2 deletions test/js/bun/util/reportError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ error
error
Uint8Array(1) [ 0 ]
error
Uint8Array(0) [ ]
Uint8Array(0) []
error
ArrayBuffer(0) [ ]
ArrayBuffer(0) []
error
ArrayBuffer(1) [ 0 ]
error: string
Expand Down
2 changes: 1 addition & 1 deletion test/js/node/crypto/node-crypto.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ describe("createHash", () => {

it("repeated calls doesnt segfault", () => {
function fn() {
crypto.createHash("sha1").update(Math.random(), "ascii").digest("base64");
crypto.createHash("sha1").update(Math.random().toString(), "ascii").digest("base64");
}

for (let i = 0; i < 10; i++) fn();
Expand Down
6 changes: 3 additions & 3 deletions test/js/node/fs/fs-oom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ setSyntheticAllocationLimitForTesting(128 * 1024 * 1024);
// /dev/zero reports a size of 0. So we need a separate test for reDgular files that are huge.
if (isPosix) {
test("fs.readFileSync(/dev/zero) should throw an OOM without crashing the process.", () => {
expect(() => readFileSync("/dev/zero")).toThrow("Out of memory");
expect(() => readFileSync("/dev/zero")).toThrow("ENOMEM: not enough memory, read '/dev/zero'");
Bun.gc(true);
});

test.each(["utf8", "ucs2", "latin1", "hex", "base64", "base64url"] as const)(
"fs.readFileSync(/dev/zero, '%s') should throw an OOM without crashing the process.",
encoding => {
expect(() => readFileSync("/dev/zero", encoding)).toThrow("Out of memory");
expect(() => readFileSync("/dev/zero", encoding)).toThrow("ENOMEM: not enough memory, read '/dev/zero'");
Bun.gc(true);
},
);
Expand All @@ -37,7 +37,7 @@ if (isLinux) {

try {
expect(() => (encoding === "buffer" ? readFileSync(memfd) : readFileSync(memfd, encoding))).toThrow(
"Out of memory",
"ENOMEM: not enough memory",
);
} finally {
Bun.gc(true);
Expand Down

0 comments on commit 1970450

Please sign in to comment.