Don't collapse newlines in error messages

master
Sven Slootweg 4 years ago
parent df9bd461a6
commit 8f2c258194

@ -1,6 +1,7 @@
"use strict";
const chalk = require("chalk");
const syncpipe = require("syncpipe");
const { validateArguments } = require("@validatem/core");
const required = require("@validatem/required");
@ -12,8 +13,27 @@ const stripErrorFromStack = require("./strip-error-from-stack");
const isInstanceOf = require("./is-instance-of");
const getChain = require("../get-chain");
function formattedErrorHeading(error, colorAll = false) {
let formattedMessage = error.message.trim().replace(/\n/g, " \\n ");
function prefixExtraLines(string, prefix) {
return string
.split("\n")
.map((line, i) => {
if (i > 0) {
return prefix + line;
} else {
return line;
}
})
.join("\n");
}
function formattedErrorHeading(error, colorAll = false, indentation) {
let formattedMessage = syncpipe(error.message, [
(_) => _.trim(),
(_) => (indentation != null)
? prefixExtraLines(_, indentation)
: _
]);
let formattedName = chalk.red(`${chalk.bold(error.name)}:`);
let coloredMessage = (colorAll === true) ? chalk.red(formattedMessage) : formattedMessage;
@ -72,7 +92,7 @@ module.exports = function renderError(_error, _options) {
// console.log(cleanStack);
return prefix + formattedErrorHeading(error);
return prefix + formattedErrorHeading(error, false, " ");
}).join("\n");
let stacktraces = detailedErrorsToDisplay.map((error, i) => {

Loading…
Cancel
Save