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

TypeError: Cannot read property 'toString' of undefined #471

Closed
ps06756 opened this issue Jul 4, 2016 · 17 comments
Closed

TypeError: Cannot read property 'toString' of undefined #471

ps06756 opened this issue Jul 4, 2016 · 17 comments
Assignees

Comments

@ps06756
Copy link

ps06756 commented Jul 4, 2016

Node version:

4.4.4

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

0.7.0

Operating system:

OSX 10.11.5 El Captain

Description of the bug:

Typerror while using shell.exec

Example ShellJS command to reproduce the error:

java -jar CMDRunner.jar --tool Reporter --generate-png test.png --input-jtl results.jtl --plugin-type ResponseTimesOverTime --width 800 --height 600

I cannot find a simple command which reproduces the above issue, I am attaching a screenshot of the error message I am getting.

shelljs_bug

@ariporad
Copy link
Contributor

ariporad commented Jul 5, 2016

Hmm... This is really quite strange...

@ps06756, would it be possible for you to share the .jar file with us? (Or does this happen with other .jar's?) I'm somewhat at a loss for what's happening.

@ps06756
Copy link
Author

ps06756 commented Jul 6, 2016

I am using the following jar.
CMDRunner.jar.zip

If I run the same command, from a terminal then the command runs without any problem.

@nfischer
Copy link
Member

@ariporad Are you still looking into this?

@nfischer
Copy link
Member

I saw a related error on an OS X Travis worker. Here's a screenshot, in case the build restarts and wipes out this log:

screenshot from 2016-07-31 13-02-49

@ariporad
Copy link
Contributor

ariporad commented Aug 1, 2016

@nfischer: I think that's related to shjs, which is in need of some help, ref #497.

@ariporad
Copy link
Contributor

ariporad commented Aug 1, 2016

@ps06756: Sorry for the delay, I've been really busy recently.

Could you try this with the #471 branch? I've added some debugging stuff which should hopefully be helpful.

@nfischer
Copy link
Member

nfischer commented Aug 1, 2016

@nfischer: I think that's related to shjs, which is in need of some help, ref #497.

Yes, that's the PR in which the error occurred. I posted it, not to suggest that it's occurring on master branch, but as an example of the error to help with debugging this issue, since neither you nor I have seen the bug pop up in our usage of ShellJS.

@ariporad
Copy link
Contributor

ariporad commented Aug 4, 2016

What?

@eisenbergrobin
Copy link

I'm getting this issue pretty frequently when running a development server with webpack:

  [491] ./~/moment/locale/lt.js/private/var/folders/ll/pd5zlkb138ldyyq6mzz9zd8h0000gn/T/shelljs_b5a18701642053f3a4d2:4
  fs.writeFileSync("/var/folders/ll/pd5zlkb138ldyyq6mzz9zd8h0000gn/T/shelljs_0cf1d4941d3414207791", err ? err.code.toString() : '0');
                                                                                                                  ^

TypeError: Cannot read property 'toString' of undefined
    at /private/var/folders/ll/pd5zlkb138ldyyq6mzz9zd8h0000gn/T/shelljs_b5a18701642053f3a4d2:4:115
    at ChildProcess.exithandler (child_process.js:220:5)
    at emitTwo (events.js:87:13)
    at ChildProcess.emit (events.js:172:7)
    at maybeClose (internal/child_process.js:821:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
exec: internal error
/script/lib/common.js:40
  if (res.code !== 0) {
         ^

TypeError: Cannot read property 'code' of null

On MacOS X 10.11.6 (El Capitan), Node 4.3.2.

I reproduce this at least twice a day. @ariporad Would you like me to try something to help out with debugging? I can run the #470 branch if you need.

ariporad added a commit that referenced this issue Aug 4, 2016
@ariporad
Copy link
Contributor

ariporad commented Aug 4, 2016

@eisenbergrobin: Sure, if you wouldn't mind trying out the debug/471 branch, that would rock. I think it should be a bit more verbose.

@eisenbergrobin
Copy link

eisenbergrobin commented Aug 5, 2016

@ariporad:

Tried putting your debug/471 branch, unfortunately it seems the code is not valid:

You are missing a trailing double-quote and comma here and a comma here.

I fixed it locally, but you might want to fix it on your branch :)

So I'm now running this, I'll get back to you if I get any interesting debug information.

@ariporad
Copy link
Contributor

ariporad commented Aug 5, 2016

@eisenbergrobin: Continually proving my geinousnessness. 😄 Fixed.

@eisenbergrobin
Copy link

@ariporad:

Reproduced it. Here is the extra information from your console.log:

[Error: stdout maxBuffer exceeded] cmd: '/bin/sh -c npm run start'

So it seems I am exceeding the max stdout output buffer...
I've reduced logging verbosity on my webpack-dev-middleware and that should mitigate the problem enough for me not to see it (fingers crossed).

Thanks for the help :)

@eisenbergrobin
Copy link

For those of you having the same issue when running a development server under webpack-dev-middleware, this occurs because the command is outputting (after a while) more than what the buffer can handle in a single command.

I fixed it by making my middleware less verbose when rebuilding:


app.use(require('webpack-dev-middleware')(compiler, {
  noInfo: true,
  stats: {
    colors: true,
    assets: false,
    version: false,
    hash: false,
    timings: false,
    chunks: false,
    chunkModules: false,
  },
}));

That means less lines are printed, and I still get information on whether the build was successful and what went wrong.

@ariporad
Copy link
Contributor

@eisenbergrobin: Have you tried changing the maxBuffer?

@eisenbergrobin
Copy link

@ariporad: Continually proving my geniusness 😄 . I had no idea I could pass options from node::child_process to shelljs::exec to handle this.

I haven't reproduced the issue since the fix described above (since my webpack output was way too verbose anyways), but I increased the buffer size in any case:

const options = {
    ...opts,
    maxBuffer: 1024 * 1000, // Increase maxBuffer on node exec for long-running 'watch' commands with a lot of output to stdout
  };
return shell.exec(cmd, options);

Thanks for your help :)

@nfischer
Copy link
Member

Sounds like the root cause of this issue has been solved, so I'll go ahead and close this. Please ping this thread if the toString issues occur for some other reason.

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

4 participants