From e811236973235ce35fc206dff077df5ad9384077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Sun, 2 Jun 2013 11:49:01 +0100 Subject: [PATCH] Print only the stack trace when verbose or the error has no code (usually something strange). --- lib/renderers/StandardRenderer.js | 10 +++++----- lib/util/cli.js | 4 ++-- lib/util/extract.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/renderers/StandardRenderer.js b/lib/renderers/StandardRenderer.js index 06c1a33c..fb2de2cc 100644 --- a/lib/renderers/StandardRenderer.js +++ b/lib/renderers/StandardRenderer.js @@ -4,7 +4,7 @@ var template = require('../util/template'); var wideCommands = ['install', 'update']; -function StandardRenderer(command, colorful) { +function StandardRenderer(command, config) { this._sizes = { id: 10, // Id max chars label: 23, // Label max chars @@ -18,7 +18,7 @@ function StandardRenderer(command, colorful) { }; this._command = command; - this._colorful = colorful == null ? true : colorful; + this._config = config; if (wideCommands.indexOf(command) === -1) { this._compact = true; @@ -48,8 +48,8 @@ StandardRenderer.prototype.error = function (err) { str += mout.string.trim(err.details) + '\n'; } - // Print stack if the error is not skippable - if (!err.skippable) { + // Print stack if verbose or the error has no code + if (this._config.verbose || !err.code) { str += '\n' + err.stack + '\n'; } @@ -177,7 +177,7 @@ StandardRenderer.prototype._prefixNotification = function (notification) { }; StandardRenderer.prototype._write = function (stream, str) { - if (!this._colorful) { + if (!this._config.color) { str = str.replace(/\x1B\[\d+m/g, ''); } diff --git a/lib/util/cli.js b/lib/util/cli.js index 5096ce68..54264643 100644 --- a/lib/util/cli.js +++ b/lib/util/cli.js @@ -39,10 +39,10 @@ function readOptions(options, argv) { function getRenderer(command, config) { if (config.json) { - return new renderers.Json(command); + return new renderers.Json(command, config); } - return new renderers.Standard(command, config.color); + return new renderers.Standard(command, config); } module.exports.readOptions = readOptions; diff --git a/lib/util/extract.js b/lib/util/extract.js index 26f44a2a..c3503ad1 100644 --- a/lib/util/extract.js +++ b/lib/util/extract.js @@ -6,6 +6,7 @@ var tar = require('tar'); var Q = require('q'); var mout = require('mout'); var junk = require('junk'); +var createError = require('./createError'); // This forces the default chunk size to something small in an attempt // to avoid issue #314 @@ -153,7 +154,7 @@ function extract(src, dest, opts) { // If extractor is null, then the archive type is unknown if (!extractor) { - return Q.reject(new Error('File "' + src + '" is not a known archive')); + return Q.reject(createError('File "' + src + '" is not a known archive', 'ENOTARCHIVE')); } // Extract archive