imq-cli
Version:
Command Line Interface for IMQ
44 lines • 1.78 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/*!
* IMQ-CLI library: error
*
* Copyright (c) 2018, Mykhailo Stadnyk <mikhus@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
const chalk_1 = require("chalk");
// that is just a printing function, no need to do specific tests
// istanbul ignore next
/**
* Prints error message to standard error output
*
* @param {Error} err - error to display message from
* @param {boolean} [withStackTrace] - if true will printError error stack
*/
function printError(err, withStackTrace = false) {
let message = err.message;
try {
let obj = JSON.parse(message);
if (obj.message && obj.errors) {
message = `${obj.message}: ${obj.errors.map((err) => err.message).join('\n')}`;
}
}
catch (err) { /* ignore */ }
process.stderr.write(chalk_1.default.bold.red(message) + '\n');
if (withStackTrace && err.stack) {
process.stderr.write(chalk_1.default.cyan(err.stack) + '\n');
}
}
exports.printError = printError;
//# sourceMappingURL=error.js.map
;