Check if path exists before returning from opendirSync - #17846
Check if path exists before returning from opendirSync#17846evanrittenhouse wants to merge 1 commit into
Conversation
paperclover
left a comment
There was a problem hiding this comment.
the problem with this approach is it will not set error.code.
| function opendirSync(path, options) { | ||
| // TODO: validatePath | ||
| // validateString(path, "path"); | ||
| if (!fs.existsSync(path)) { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
accessSync won't error if it's not a directory
There was a problem hiding this comment.
true. then instead, this PR should expose an opendir binding in src/bun.js/node/node_fs_binding.zig to fs.ts, and have a matching implementation function in src/bun.js/node/node_fs.zig. this function would return a directory file descriptor. Then, there can be internal variants of readdir that work on this file descriptor.
There was a problem hiding this comment.
Thanks for the pointers. I figured this would involve some Zig bindings, but wanted to ensure that there wasn't anything in JS-land that I was missing. I'm starting to work on the bindings now, should hopefully have something up this week, time permitting
| describe("opendirSync", () => { | ||
| it("should throw ENOENT on a nonexistent directory", () => { | ||
| const dirName = Math.random().toString(8); | ||
| expect(() => opendirSync(dirName)).toThrow("ENOENT"); |
There was a problem hiding this comment.
.toThrow({ code: "ENOENT" })
|
Sorry, work has been nuts. I've been making progress on this but haven't quite gotten the time to finish it up yet |
|
Thanks for picking this up. This was fixed on main in #31830: Since the bug this draft targeted is fixed, closing it. |
Closes #17581
What does this PR do?
How did you verify your code works?
One thing I don't quite see a pattern for yet is returning a system error (e.g.
ENOENT) from JS code, but it seems like the typical way to do that is by putting the implementation into the Zig code.I figured I'd raise the PR while I look at how to do that in case there's a way to do it from JS though