Repository navigation
fix(windows): resolve mkdir(".") ENOENT error #25207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -931,6 +931,13 @@ pub fn normalizeStringGenericTZ( | |
| buf_i += 1; | ||
| } | ||
|
|
||
| // If normalization resulted in an empty path, return "." | ||
| // This happens when the input is just "." or consists only of dots/separators that get normalized away | ||
| if (buf_i == buf_start and path_.len > 0) { | ||
| buf[buf_i] = '.'; | ||
| buf_i += 1; | ||
| } | ||
|
|
||
|
Comment on lines
+934
to
+940
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major LGTM! Essential fix to prevent empty normalized paths. This guard correctly addresses the root cause where path normalization could produce an empty string from inputs like "." or paths consisting only of separators and dots. The condition This change works in conjunction with the 🤖 Prompt for AI Agents |
||
| if (options.zero_terminate) { | ||
| buf[buf_i] = 0; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,110 @@ | ||||||||||||||
| import { expect, test } from "bun:test"; | ||||||||||||||
| import { bunEnv, bunExe, isWindows } from "harness"; | ||||||||||||||
|
|
||||||||||||||
| // https://github.com/oven-sh/bun/issues/21901 | ||||||||||||||
| test("mkdir('.') should succeed with recursive option on Windows", async () => { | ||||||||||||||
| if (!isWindows) { | ||||||||||||||
| test.skip(); | ||||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+5
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider using The current skip logic is correct, but you can simplify it using -test("mkdir('.') should succeed with recursive option on Windows", async () => {
- if (!isWindows) {
- test.skip();
- return;
- }
+test.skipIf(!isWindows)("mkdir('.') should succeed with recursive option on Windows", async () => {This is more idiomatic and doesn't require the early return. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| // Test mkdirSync with recursive option | ||||||||||||||
| { | ||||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||||
| cmd: [ | ||||||||||||||
| bunExe(), | ||||||||||||||
| "-e", | ||||||||||||||
| ` | ||||||||||||||
| const fs = require('fs'); | ||||||||||||||
| try { | ||||||||||||||
| fs.mkdirSync('.', { recursive: true }); | ||||||||||||||
| console.log('mkdirSync success'); | ||||||||||||||
| } catch (err) { | ||||||||||||||
| console.error('mkdirSync error:', err.message); | ||||||||||||||
| process.exit(1); | ||||||||||||||
| } | ||||||||||||||
| `, | ||||||||||||||
| ], | ||||||||||||||
| env: bunEnv, | ||||||||||||||
| stdout: "pipe", | ||||||||||||||
| stderr: "pipe", | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||||||||||||||
|
|
||||||||||||||
| expect(stdout.trim()).toBe("mkdirSync success"); | ||||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+11
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider validating or logging stderr for better debugging. The test captures stderr but never checks or logs it. Consider adding stderr validation or logging it when the test fails: const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
+expect(stderr.trim()).toBe(""); // or log stderr on failure
expect(stdout.trim()).toBe("mkdirSync success");
expect(exitCode).toBe(0);This would make debugging easier if the test fails unexpectedly. Apply this suggestion to all three test blocks (lines 11-37, 39-67, and 69-109). 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| // Test mkdir with recursive option (promise) | ||||||||||||||
| { | ||||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||||
| cmd: [ | ||||||||||||||
| bunExe(), | ||||||||||||||
| "-e", | ||||||||||||||
| ` | ||||||||||||||
| const fs = require('fs').promises; | ||||||||||||||
| (async () => { | ||||||||||||||
| try { | ||||||||||||||
| await fs.mkdir('.', { recursive: true }); | ||||||||||||||
| console.log('mkdir success'); | ||||||||||||||
| } catch (err) { | ||||||||||||||
| console.error('mkdir error:', err.message); | ||||||||||||||
| process.exit(1); | ||||||||||||||
| } | ||||||||||||||
| })(); | ||||||||||||||
| `, | ||||||||||||||
| ], | ||||||||||||||
| env: bunEnv, | ||||||||||||||
| stdout: "pipe", | ||||||||||||||
| stderr: "pipe", | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||||||||||||||
|
|
||||||||||||||
| expect(stdout.trim()).toBe("mkdir success"); | ||||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Test Promise.allSettled with multiple mkdir('.') calls | ||||||||||||||
| { | ||||||||||||||
| await using proc = Bun.spawn({ | ||||||||||||||
| cmd: [ | ||||||||||||||
| bunExe(), | ||||||||||||||
| "-e", | ||||||||||||||
| ` | ||||||||||||||
| const fs = require('fs').promises; | ||||||||||||||
| (async () => { | ||||||||||||||
| try { | ||||||||||||||
| const results = await Promise.allSettled([ | ||||||||||||||
| fs.mkdir('.', { recursive: true }), | ||||||||||||||
| fs.mkdir('.', { recursive: true }), | ||||||||||||||
| fs.mkdir('.', { recursive: true }), | ||||||||||||||
| ]); | ||||||||||||||
|
|
||||||||||||||
| const allSucceeded = results.every(r => r.status === 'fulfilled'); | ||||||||||||||
| if (allSucceeded) { | ||||||||||||||
| console.log('Promise.allSettled success'); | ||||||||||||||
| } else { | ||||||||||||||
| const failed = results.filter(r => r.status === 'rejected'); | ||||||||||||||
| console.error('Some promises failed:', failed.map(f => f.reason?.message).join(', ')); | ||||||||||||||
| process.exit(1); | ||||||||||||||
| } | ||||||||||||||
| } catch (err) { | ||||||||||||||
| console.error('Promise.allSettled error:', err.message); | ||||||||||||||
| process.exit(1); | ||||||||||||||
| } | ||||||||||||||
| })(); | ||||||||||||||
| `, | ||||||||||||||
| ], | ||||||||||||||
| env: bunEnv, | ||||||||||||||
| stdout: "pipe", | ||||||||||||||
| stderr: "pipe", | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||||||||||||||
|
|
||||||||||||||
| expect(stdout.trim()).toBe("Promise.allSettled success"); | ||||||||||||||
| expect(exitCode).toBe(0); | ||||||||||||||
| } | ||||||||||||||
| }); | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Replace panic with graceful error handling for getcwd failure.
Using
@panic("Error getting cwd")on line 639 will crash the entire Bun process ifgetcwd()fails. This can occur in legitimate scenarios such as:While the fix for resolving relative paths is correct, the error handling needs improvement. Consider one of these approaches:
Example fix:
Additionally, check if similar panic calls elsewhere in this function (like line 576, 583, 632) should be addressed consistently.
🤖 Prompt for AI Agents