Skip to content

fix: report chdir errors from cd#1253

Open
lawrence3699 wants to merge 1 commit into
shelljs:mainfrom
lawrence3699:fix/cd-worker-error
Open

fix: report chdir errors from cd#1253
lawrence3699 wants to merge 1 commit into
shelljs:mainfrom
lawrence3699:fix/cd-worker-error

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #1112.

When process.chdir() fails for an existing directory, cd() currently reclassifies the target as not a directory. In worker threads this hides Node's actual process.chdir() is not supported in workers error.

This keeps the existing no such file or directory and not a directory paths, but reports the original process.chdir() error when the target exists and is a directory.

Validation:

  • npx ava test/cd.js --match='reports process.chdir() errors for existing directories'
  • npx ava test/cd.js
  • npm run test-with-coverage -- test/cd.js
  • npm run lint
  • git diff --check

I also ran npm test; the cd tests passed, and the remaining local failures reproduced on a clean checkout before this change: chmod › Test setgid and four ls › long option assertions where this environment reports gid 0.

Comment thread test/cd.js
t.is(result.stderr, 'cd: not a directory: test/resources/file1');
});

test('reports process.chdir() errors for existing directories', async t => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this test case to "shell.cd() not supported in workers" or something like that?

@codecov
Copy link
Copy Markdown

codecov Bot commented May 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (2809a87) to head (0792b58).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1253   +/-   ##
=======================================
  Coverage   97.09%   97.10%           
=======================================
  Files          36       36           
  Lines        1517     1519    +2     
=======================================
+ Hits         1473     1475    +2     
  Misses         44       44           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

The cd command can report an incorrect error when executing in a worker

2 participants