Skip to content

Commit

Permalink
fix(CLI): Ensure to strip error messages from colors in modern logs
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Sep 17, 2021
1 parent 655140b commit 80005aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/cli/handle-error.js
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const isObject = require('type/object/is');
const chalk = require('chalk');
const stripAnsi = require('strip-ansi');
const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
const resolveLocalServerlessPath = require('./resolve-local-serverless-path');
const slsVersion = require('./../../package').version;
Expand Down Expand Up @@ -145,8 +146,11 @@ module.exports = async (exception, options = {}) => {
)
);

const errorMsg =
exceptionTokens.stack && !isUserError ? exceptionTokens.stack : exceptionTokens.message;
// TODO: Ideally after migrating to new logger complete this strip should not be needed
// (it can be removed after we clear all chalk error message decorations from internals)
const errorMsg = stripAnsi(
exceptionTokens.stack && !isUserError ? exceptionTokens.stack : exceptionTokens.message
);
writeText(style.error('\nError:'));
if (errorMsg) {
writeText(` ${errorMsg.split('\n').join('\n ')}`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -70,6 +70,7 @@
"replaceall": "^0.1.6",
"semver": "^7.3.5",
"signal-exit": "^3.0.3",
"strip-ansi": "^6.0.0",
"tabtab": "^3.0.2",
"tar": "^6.1.11",
"timers-ext": "^0.1.7",
Expand Down Expand Up @@ -105,7 +106,6 @@
"sinon": "^11.1.2",
"sinon-chai": "^3.7.0",
"standard-version": "^9.3.1",
"strip-ansi": "^6.0.0",
"ws": "^7.5.5",
"xml2js": "^0.4.23"
},
Expand Down

0 comments on commit 80005aa

Please sign in to comment.