Skip to content

Fix duplicate PWD error messages when directory is deleted#17355

Open
po-nuvai wants to merge 1 commit intonushell:mainfrom
po-nuvai:fix-duplicate-pwd-errors
Open

Fix duplicate PWD error messages when directory is deleted#17355
po-nuvai wants to merge 1 commit intonushell:mainfrom
po-nuvai:fix-duplicate-pwd-errors

Conversation

@po-nuvai
Copy link

Summary

  • Fixes the annoying 4-5 duplicate "$env.PWD points to a non-existent directory" errors when running commands from a deleted directory
  • Adds a cwd_error_reported_this_cycle flag to track when a cwd error has been reported in the current REPL iteration
  • Only reports the error once per REPL cycle, subsequent cwd checks skip validation if we already know it's bad

Test plan

  1. Start nushell in an interactive session
  2. Create and cd into a temporary directory: mkdir /tmp/test_dir && cd /tmp/test_dir
  3. In another terminal, delete that directory: rm -rf /tmp/test_dir
  4. Back in nushell, run any command like ls
  5. Verify that the "$env.PWD points to a non-existent directory" error only appears once instead of 4-5 times

Closes #17284

When running commands from a deleted directory, the error message
"$env.PWD points to a non-existent directory" was printed 4-5 times
because multiple operations in the REPL loop independently check cwd.

This fix adds a `cwd_error_reported_this_cycle` flag to EngineState
that tracks whether a cwd error has already been reported in the
current REPL iteration. The flag is reset at the start of each
iteration and checked before reporting subsequent cwd errors.

Closes nushell#17284
@fdncred
Copy link
Contributor

fdncred commented Jan 15, 2026

Thanks for the PR.

  1. When is reset called? Is it possible to get stuck with it being true by accident?
  2. We need some positive and negative tests.
  3. What does "this cycle" mean in your comments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated "$env.PWD points to a non-existent directory" errors

2 participants