question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

shellJS swallows Heroku CLI output and fails with undefined error

See original GitHub issue

Node version 12.16.1

ShellJS version “^0.8.3”

Operating system: Ubuntu 18

Description of the bug: ShellJS fails without any stdout when running Heroku commands

Example ShellJS command to reproduce the error:

Install the Heroku CLI

I am evaluating the use of ShellJS in helping me move my deployment/CI pipeline to TS instead of a bunch of bash scripts.

Everything is currently working fine in bash land, but when I try running heroku commands in ShellJS it just errors out with no output of any kind.

For example

      shell.set(`-v`)
      const result = shell.exec(`heroku --help`);
      console.log(result);

      const child = shell.exec(`heroku login`, {async: true});
      child.stdout.on('data', function(data) {
        console.log(data);
      });

Results in:

  console.log tests/create_app.test.ts:25
    [String: ''] {
      stdout: '',
      stderr: '',
      code: 0,
      cat: [Function: bound ],
      exec: [Function: bound ],
      grep: [Function: bound ],
      head: [Function: bound ],
      sed: [Function: bound ],
      sort: [Function: bound ],
      tail: [Function: bound ],
      to: [Function: bound ],
      toEnd: [Function: bound ],
      uniq: [Function: bound ]
    }

Some of the processes hang long enough that it makes me think something is happening, but without any way to debug it is hard to tell.

My current handler for exec looks like this,

  static async execAsync(cmd, opts={}): Promise<string> {
    return new Promise(function(resolve, reject) {
      // Execute the command, reject if we exit non-zero (i.e. error)
      const child = shell.exec(cmd, {shell: '/bin/bash', ...opts}, function(code, stdout) {

        if (code != 0) return reject(new Error(stdout));
        return resolve(stdout);
      });
      child.stdout.on('data', function(data) {
        console.log(data);
      });
    });
  }

If this is problem with the Heroku CLI I understand, but I find that hard to believe considering that all of these commands work perfectly fine elsewhere.

Linking to the Heroku CLI ticket for reference: https://github.com/heroku/cli/issues/1478

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
nfischercommented, Apr 14, 2020

console.error node_modules/shelljs/src/common.js:327

It’s unclear where this output is coming from. Might help to change your log line to something like:

      child.stdout.on('data', function(data) {
        console.log('from child stdout: ' + data);
      });
      child.stderr.on('data', function(data) {
        console.log('from child stderr: ' + data);
      });

You could also add { silent: true, async: true } to the exec call, or else you’ll get double-logging.

0reactions
austinrivascommented, Oct 17, 2020

@nfischer I’m closing this as the issue seems to be related to the shell executing the heroku commands and not your library, thanks for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release Phase | Heroku Dev Center
Release command failure; Checking release status & logs; Canceling a release command; Review apps and the postdeploy script ...
Read more >
The definitive Node.js handbook - Medium
The first value, test , is the output we told the console to print, then we get undefined which is the return value...
Read more >
Node.js Handbook - lcg.ufrj
The first value, test , is the output we told the console to print, then we get undefined which is the return value...
Read more >
Node.js Handbook - Amazon S3
How to print to the command line console using Node, from the basic ... Or a bug in the latest release of a...
Read more >
Node.js Notes for Professionals
Section 13.2: process.argv command line arguments ... errors thrown in a promise that are not caught results in the error being swallowed, which...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found