-
Notifications
You must be signed in to change notification settings - Fork 5k
getcwd: report CurrentWorkingDirectoryUnlinked from a deleted cwd again #32357
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🟡 The PR description says "Every other bun_sys::getcwd caller handles its error locally," but bun_install's own
--cwdparser atsrc/install/PackageManager/CommandLineArguments.rs:1554still callsbun_sys::getcwd(&mut buf[..])?and propagates ENOENT tohandle_root_error— package-manager commands skiparguments::parsebecauseUSES_GLOBAL_OPTIONS[InstallCommand]is false. It's the structural twin of the--cwdsite fixed here, sobun install --cwd .from a deleted directory still prints the generic "Bun could not find a file" fallback; switching that call tobun_core::getcwdwould close the class.Extended reasoning...
What the bug is
The PR converts three
bun_sys::getcwdcall sites tobun_core::getcwdso that a deleted cwd surfacesCurrentWorkingDirectoryUnlinkedathandle_root_errorand prints the actionable "The current working directory was deleted…" hint. The PR description justifies stopping at three sites with: "Every other bun_sys::getcwd caller handles its error locally and is unchanged." That claim is incorrect for the package-manager--cwdparser, which still propagates a bare ENOENT all the way tohandle_root_errorand hits the generic fallback this PR set out to eliminate.The specific code path
Package-manager subcommands (
install,add,remove,update,link,pm, …) do not go through the modifiedarguments::parseinsrc/runtime/cli/Arguments.rs.USES_GLOBAL_OPTIONS[Tag::InstallCommand]isfalse(src/options_types/command_tag.rs:266), socreate_context_data()atsrc/runtime/cli/mod.rs:1136skipsarguments::parseentirely for the whole family. Instead these commands parse--cwdinsidebun_install::CommandLineArguments::parse:Why the existing changes don't cover it
Arguments.rs:837conversion never runs for install-family commands (gated out byUSES_GLOBAL_OPTIONS).resolver/lib.rsconversion (FileSystem::init(None)) is reached later, insidePackageManager::init(src/install/PackageManager.rs:1498), but the--cwd .branch fails beforePackageManager::initis called — so the resolver-side fix never fires on this path.src/sys/Error.rs(commit 4c99108 "Produce CurrentWorkingDirectoryUnlinked only from bun_core::getcwd" removed the cross-cuttingto_named_core_errapproach), sobun_sys::getcwdstill surfaces a bare errno.Step-by-step proof
mkdir /tmp/gone && cd /tmp/gone && rmdir /tmp/gone && bun install --cwd .USES_GLOBAL_OPTIONS[InstallCommand] == false→create_context_dataskipsarguments::parse; dispatch callsinstall()→bun_install::CommandLineArguments::parse.--cwdis".", socwd_[0] == b'.'→ line 1554 callsbun_sys::getcwd(&mut buf[..]), which fails witherrno == ENOENT.?converts viaFrom<bun_sys::Error> for bun_install::Error(src/install/error.rs:405-408) →bun_install::Error::Sys(SystemErrno::ENOENT).InstallCommand::handle_error(src/runtime/cli/install_command.rs:29-44) matches onlyInstallFailed/InvalidPackageJSON, so the error propagates asbun_runtime::Error::Install(...)→main→handle_root_error.name()chain:runtime::Error::Install(e).name()→install::Error::Sys(e).name()(src/install/error.rs:381) →<&str>::from(SystemErrno::ENOENT)→"ENOENT".handle_root_errormatches theb"ENOENT"arm atsrc/crash_handler/lib.rs:1423and prints:CurrentWorkingDirectoryUnlinkedhint.Impact
Low. The trigger requires the combination of (a) a deleted cwd and (b) an explicit relative
--cwdargument to a package-manager subcommand. No crash or incorrect behavior; the user just gets the unhelpful message instead of the hint. But perREVIEW.md("Fix the whole class in the same PR — same-class sites are ONE concern, not scope creep"), this is a same-class sibling of the three converted sites: it resolves a relative--cwdagainstgetcwd()and propagates the failure tohandle_root_error, exactly like theArguments.rs:837twin. And the "intentionally excluded" rationale in the PR description is factually wrong for this site — it does not handle its error locally.Fix
One-line: switch
src/install/PackageManager/CommandLineArguments.rs:1554frombun_sys::getcwdtobun_core::getcwd, matching the pattern applied atArguments.rs:837:(and either update the PR description's exclusion claim, or drop it).