-
-
Notifications
You must be signed in to change notification settings - Fork 197
CLI does not respect shelljs errors #1594
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
Comments
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. |
One solution to this problem is checking each individual place we use shelljs and figure out what behavior we want to have. This way we'll have full control over shelljs behavior. |
@Plamen5kov in this case I would recommend extracting all shelljs calls in a separate class that will be resolved via $injector. |
@rosen-vladimirov I'm still struggling to see the best possible solution, because we need to change the behavior depending on the place of usage. We might have a scenario, where we have and expected error and can continue execution, and a case where the same command needs to have different consequences. It's hard to see a general solution that will cover all problems. It's a good idea to wrap shelljs command, but that won't help with individual logic we have to implement on shelljs failure. Another option is to log every error, but continue execution. That way we at least shot what possible errors might have caused a failure. |
@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
class Shelljs implements IShelljs {
...
}
$injector.register("shelljs", shelljs);
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);
// 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
} |
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 callingtns platform add [email protected]
for example.So consider respecting the errors of shelljs, but make sure all operations work.
The text was updated successfully, but these errors were encountered: