fix(CLI): don't print stack traces by default (#1206)

Currently, the Etcher CLI will print scary stack traces for every single
error (e.g: if you forgot to pass an image to the tool), given that
`errors.getDescription()` will return a stack trace if no other
description could be found.

This commit introduces an `ETCHER_CLI_DEBUG` environment variable, which
when set, it will cause the Etcher CLI to output stack traces, plus a
boolean `userFriendlyDescriptionsOnly` option to
`errors.getDescription()`, so we can control whether
`errors.getDescription()` returns things like stack traces, or
stringified error objects.

Change-Type: minor
Changelog-Entry: Don't print stack traces by default in the CLI.
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti
2017-03-28 09:43:15 -04:00
committed by GitHub
parent 396145d625
commit 57952f6f55
4 changed files with 79 additions and 2 deletions

View File

@@ -31,10 +31,17 @@ const errors = require('../shared/errors');
*/
exports.printError = (error) => {
const title = errors.getTitle(error);
const description = errors.getDescription(error);
const description = errors.getDescription(error, {
userFriendlyDescriptionsOnly: true
});
console.error(chalk.red(title));
if (description) {
console.error(`\n${chalk.red(description)}`);
}
if (process.env.ETCHER_CLI_DEBUG && error.stack) {
console.error(`\n${chalk.red(error.stack)}`);
}
};