Skip to content
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

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

Open
ColinEberhardt opened this issue Dec 14, 2022 · 2 comments

Comments

@ColinEberhardt
Copy link

Node version (or tell us if you're using electron or some other framework):

v16.14.2

ShellJS version (the most recent version/Github branch you see the bug on):

v0.8.5

Operating system:

Mac

Description of the bug:

When trying to use shell.cd within a worker specifying a folder which does exist, the cd command fails with the following error:

not a directory: foo

However, the underlying process.chdir command that shell uses, reports the following:

process.chdir() is not supported in workers
@nfischer
Copy link
Member

ShellJS is designed to operate on environmental variables, which are global state. I glanced at https://nodejs.org/api/worker_threads.html#class-worker, but unfortunately it looks like this doesn't allow code in workers to modify global state in this way. This doesn't seem like something we can support unfortunately.

I agree the error message is misleading. I'll keep this issue open to detect this case and print a more reasonable error message.

@nfischer
Copy link
Member

nfischer commented Sep 7, 2023

Issue #1132 also points out:

The current implementation of cd.js is swallowing the actual error. The exception caught in line 27 (e) is not logged nor used further in the the error handling. This hides errors such as chdir not supported in worker threads or other causes not covered by the current handling error code in this file.

I still agree we need to surface this error message better. I'm open to suggestions (or PRs) to improve the error handling.

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

No branches or pull requests

2 participants