From 4b44e01a323aa9d2c0965e92c1796158cb36ce5a Mon Sep 17 00:00:00 2001 From: Alexey Lavinsky Date: Wed, 23 Sep 2020 18:40:02 +0300 Subject: [PATCH] feat: improve error and warning messages (#485) --- src/Error.js | 4 +++- src/Warning.js | 3 ++- test/__snapshots__/loader.test.js.snap | 26 +++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Error.js b/src/Error.js index bb890ce3..1b2d6df2 100644 --- a/src/Error.js +++ b/src/Error.js @@ -12,7 +12,7 @@ class SyntaxError extends Error { constructor(error) { super(error); - const { line, column, reason } = error; + const { line, column, reason, plugin, file } = error; this.name = 'SyntaxError'; @@ -22,6 +22,8 @@ class SyntaxError extends Error { this.message += `(${line}:${column}) `; } + this.message += plugin ? `${plugin}: ` : ''; + this.message += file ? `${file} ` : ' '; this.message += `${reason}`; const code = error.showSourceCode(); diff --git a/src/Warning.js b/src/Warning.js index 4b3bd322..bea16fe0 100644 --- a/src/Warning.js +++ b/src/Warning.js @@ -12,7 +12,7 @@ class Warning extends Error { constructor(warning) { super(warning); - const { text, line, column } = warning; + const { text, line, column, plugin } = warning; this.name = 'Warning'; @@ -22,6 +22,7 @@ class Warning extends Error { this.message += `(${line}:${column}) `; } + this.message += plugin ? `${plugin}: ` : ''; this.message += `${text}`; this.stack = false; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index af8bb4c4..e63f9610 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -58,51 +58,51 @@ Array [ "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(10:3) ", +(10:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(14:3) ", +(14:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(18:3) ", +(18:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(19:3) ", +(19:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(23:3) ", +(23:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(24:3) ", +(24:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(29:5) ", +(29:5) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(2:3) ", +(2:3) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(32:7) ", +(32:7) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(36:7) ", +(36:7) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(41:5) ", +(41:5) postcss-plugin: ", "ModuleWarning: Module Warning (from \`replaced original path\`): Warning -(6:3) ", +(6:3) postcss-plugin: ", ] `; @@ -162,7 +162,7 @@ Array [ "ModuleBuildError: Module build failed (from \`replaced original path\`): SyntaxError -(1:3) Unnecessary curly bracket +(1:3) /test/fixtures/css/style.css Unnecessary curly bracket > 1 | a { | ^