Visitar URL original
The cd command can report an incorrect error when executing in a worker · Issue #1112 · shelljs/shelljs · GitHub
Skip to content

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

Description

@ColinEberhardt

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

Activity

  1. nfischer commented on Dec 16, 2022

    @nfischer
    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.

  2. nfischer commented on Sep 7, 2023

    @nfischer
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions