Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/runtime/webcore/blob/Store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,16 @@ impl FileExt for File {
None,
))
}
PathOrFileDescriptor::Fd(_) => Ok(JSPromise::resolved_promise_value(
PathOrFileDescriptor::Fd(_) => Ok(JSPromise::rejected_promise(
cx.global(),
// `JSGlobalObject::create_invalid_args` lives in the still-gated
// `JSGlobalObject.rs`; `ERR_INVALID_ARG_TYPE` (lib.rs) is the
// same `ErrorCode::INVALID_ARG_TYPE.fmt(...)` body.
cx.global().ERR_INVALID_ARG_TYPE(format_args!(
"Is not possible to unlink a file descriptor"
)),
)),
)
.to_js()),
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/js/web/fetch/blob-write.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect, test } from "bun:test";
import { closeSync, openSync } from "fs";
import { expectMaxObjectTypeCount, tempDir, tempDirWithFiles } from "harness";
import path from "path";

Expand Down Expand Up @@ -55,6 +56,23 @@ test("Bun.file(path).delete() does not throw", async () => {
expect(await Bun.file(path.join(dir, "a")).exists()).toBe(false);
});

// A file made from a descriptor has no path to unlink.
test.each(["unlink", "delete"] as const)("Bun.file(fd).%s() rejects", async method => {
await using dir = tempDir("bun-unlink-fd", { a: "Hello, world!" });
const fd = openSync(path.join(dir, "a"), "r");
try {
const promise = Bun.file(fd)[method]();
await expect(promise).rejects.toBeInstanceOf(TypeError);
await expect(promise).rejects.toMatchObject({
code: "ERR_INVALID_ARG_TYPE",
message: "Is not possible to unlink a file descriptor",
});
} finally {
closeSync(fd);
}
expect(await Bun.file(path.join(dir, "a")).exists()).toBe(true);
});

test("blob.writer() throws for data-backed blob", () => {
const blob = new Blob(["Hello, world!"]) as any;
expect(() => blob.writer()).toThrowErrorMatchingInlineSnapshot(
Expand Down
Loading