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.

CLI does not respect shelljs errors

See original GitHub issue

Shelljs module does not fail in case shelljs.config.fatal is not set to true. However setting it true leads to some unexpected issues - the shelljs silently exits the process when calling tns platform add android@1.3.0 for example. So consider respecting the errors of shelljs, but make sure all operations work.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
slavchevcommented, Nov 14, 2016

I think we should increase the priority of this issue as I was debugging entirely different problem only to find that there were silent/missing error handling.

1reaction
rosen-vladimirovcommented, Dec 16, 2016

@Plamen5kov I think in most of the cases we would like to stop the execution in case shelljs encounters an error. However (as far as I remember), setting shelljs.config.fatal breaks the process immediately, so we have no chance to catch this. My suggestion is:

  1. Implement a wrapper for shelljs:
class Shelljs implements IShelljs {
...
}
$injector.register("shelljs", shelljs);
  1. Add a method in the new class, that executes shelljs action, checks for error and throws it in case there’s any error:
import * as shelljs from "shelljs";

class Shelljs implements IShelljs {
    constructor(private $logger: ILogger) { }
    public executeAction(command: string, commandArgs: string[]): any {
        const result = shelljs[command].apply(null, commandArgs);
        const err = shelljs.error();
        if (err) {
            this.$logger.trace("Encountered shelljs.error: ", err);
            throw new Error(err);
        }

        return result;
   }
}
$injector.register("shelljs", Shelljs);
  1. Use the method anywhere you need shelljs. In case on a specific place you do not want to fail, you can try-catch the code there and continue the execution. Another option is to pass additional flag to the executeAction method.
// This will fail in case error is encountered:
this.$shelljs.executeAction('cp', ["-r", "./my-dir", "./my-dir2"]);

// This will not fail in case error is encountered:
try {
    this.$shelljs.executeAction('cp', ["-r", "./my-dir", "./my-dir2"]);
} catch (err) {
    // do smth with the error
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS: How to synchronously exewcute shell command and ...
The README of shell.js explains: Executes the given command synchronously, unless otherwise specified. When in synchronous mode, this returns a ...
Read more >
shelljs | Yarn - Package Manager
ShellJS is a portable (Windows/Linux/OS X) implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate...
Read more >
gist-charts/node_modules/shelljs/CHANGELOG.md - GitLab
Snyk vulnerability DB reporting command injection vulnerability in ... ShellJS doesn't respect NPM Registry being set outside of it #761 ...
Read more >
mesonet.org/scripts/okfire/node_modules/ocspackage...
[\#639](https://github.com/shelljs/shelljs/issues/639) - mkdir fails with ... parseOptions should throw an error if the option string doesn't start with ...
Read more >
Working with JavaScript in Visual Studio Code
Configuration options from your jsconfig or tsconfig (such as target ) are not respected. Only syntax errors are reported. Semantic errors — such...
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