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

In the form of grep where the 2nd argument is an Array, if one of the items in the Array points to a directory, ShellJS will crash #997

Closed
bedney opened this issue May 26, 2020 · 1 comment
Labels

Comments

@bedney
Copy link

bedney commented May 26, 2020

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

10.17.0

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

0.8.3

Operating system:

Mac OSX

Description of the bug:

When using grep(), if you're using the form where you hand in a file_array and one of the files is actually a directory, ShellJS will crash.

Example ShellJS command to reproduce the error:

This will crash when it reaches directoryname:

sh = require('shelljs');
let my_file_array = ['filename1', 'filename2', 'directoryname'];
sh.grep(/hi there/, my_file_array);
@nfischer
Copy link
Member

The trace I got was:

[PATH REDACTED]/shelljs/src/common.js:399
        throw e;
        ^

Error [ShellJSInternalError]: EISDIR: illegal operation on a directory, read
    at Object.readSync (fs.js:524:3)
    at tryReadSync (fs.js:349:20)
    at Object.readFileSync (fs.js:386:19)
    at [PATH REDACTED]/shelljs/src/grep.js:55:45
    at Array.forEach (<anonymous>)
    at Object._grep ([PATH REDACTED]/shelljs/src/grep.js:49:9)
    at Object.grep ([PATH REDACTED]/shelljs/src/common.js:384:25)
    at Object.<anonymous> (/home/nfischer/shelljscrash/index.js:4:4)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) {
  errno: -21,
  syscall: 'read',
  code: 'EISDIR'
}

I think this is WAI. grep does not support directory arguments (see https://github.com/shelljs/shelljs#grepoptions-regex_filter-file--file-). We don't currently support the -R flag, although I filed #998 to track this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants