shelljs icon indicating copy to clipboard operation
shelljs copied to clipboard

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

Open ColinEberhardt opened this issue 3 years ago • 2 comments

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

ColinEberhardt avatar Dec 14 '22 22:12 ColinEberhardt

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 avatar Dec 16 '22 07:12 nfischer

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.

nfischer avatar Sep 07 '23 05:09 nfischer