Skip to content

Commit

Permalink
feat: improve error and warning messages (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-Bernardito authored Sep 23, 2020
1 parent 7bf896a commit 4b44e01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/Error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -22,6 +22,8 @@ class SyntaxError extends Error {
this.message += `(${line}:${column}) `;
}

this.message += plugin ? `${plugin}: ` : '';
this.message += file ? `${file} ` : '<css input> ';
this.message += `${reason}`;

const code = error.showSourceCode();
Expand Down
3 changes: 2 additions & 1 deletion src/Warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -22,6 +22,7 @@ class Warning extends Error {
this.message += `(${line}:${column}) `;
}

this.message += plugin ? `${plugin}: ` : '';
this.message += `${text}`;

this.stack = false;
Expand Down
26 changes: 13 additions & 13 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -58,51 +58,51 @@ Array [
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(10:3) <Message>",
(10:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(14:3) <Message>",
(14:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(18:3) <Message>",
(18:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(19:3) <Message>",
(19:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(23:3) <Message>",
(23:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(24:3) <Message>",
(24:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(29:5) <Message>",
(29:5) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(2:3) <Message>",
(2:3) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(32:7) <Message>",
(32:7) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(36:7) <Message>",
(36:7) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(41:5) <Message>",
(41:5) postcss-plugin: <Message>",
"ModuleWarning: Module Warning (from \`replaced original path\`):
Warning
(6:3) <Message>",
(6:3) postcss-plugin: <Message>",
]
`;
Expand Down Expand Up @@ -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 {
| ^
Expand Down

0 comments on commit 4b44e01

Please sign in to comment.