Skip to content

Commit 4b44e01

Browse files
feat: improve error and warning messages (#485)
1 parent 7bf896a commit 4b44e01

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/Error.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SyntaxError extends Error {
1212
constructor(error) {
1313
super(error);
1414

15-
const { line, column, reason } = error;
15+
const { line, column, reason, plugin, file } = error;
1616

1717
this.name = 'SyntaxError';
1818

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

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

2729
const code = error.showSourceCode();

src/Warning.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Warning extends Error {
1212
constructor(warning) {
1313
super(warning);
1414

15-
const { text, line, column } = warning;
15+
const { text, line, column, plugin } = warning;
1616

1717
this.name = 'Warning';
1818

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

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

2728
this.stack = false;

test/__snapshots__/loader.test.js.snap

+13-13
Original file line numberDiff line numberDiff line change
@@ -58,51 +58,51 @@ Array [
5858
"ModuleWarning: Module Warning (from \`replaced original path\`):
5959
Warning
6060
61-
(10:3) <Message>",
61+
(10:3) postcss-plugin: <Message>",
6262
"ModuleWarning: Module Warning (from \`replaced original path\`):
6363
Warning
6464
65-
(14:3) <Message>",
65+
(14:3) postcss-plugin: <Message>",
6666
"ModuleWarning: Module Warning (from \`replaced original path\`):
6767
Warning
6868
69-
(18:3) <Message>",
69+
(18:3) postcss-plugin: <Message>",
7070
"ModuleWarning: Module Warning (from \`replaced original path\`):
7171
Warning
7272
73-
(19:3) <Message>",
73+
(19:3) postcss-plugin: <Message>",
7474
"ModuleWarning: Module Warning (from \`replaced original path\`):
7575
Warning
7676
77-
(23:3) <Message>",
77+
(23:3) postcss-plugin: <Message>",
7878
"ModuleWarning: Module Warning (from \`replaced original path\`):
7979
Warning
8080
81-
(24:3) <Message>",
81+
(24:3) postcss-plugin: <Message>",
8282
"ModuleWarning: Module Warning (from \`replaced original path\`):
8383
Warning
8484
85-
(29:5) <Message>",
85+
(29:5) postcss-plugin: <Message>",
8686
"ModuleWarning: Module Warning (from \`replaced original path\`):
8787
Warning
8888
89-
(2:3) <Message>",
89+
(2:3) postcss-plugin: <Message>",
9090
"ModuleWarning: Module Warning (from \`replaced original path\`):
9191
Warning
9292
93-
(32:7) <Message>",
93+
(32:7) postcss-plugin: <Message>",
9494
"ModuleWarning: Module Warning (from \`replaced original path\`):
9595
Warning
9696
97-
(36:7) <Message>",
97+
(36:7) postcss-plugin: <Message>",
9898
"ModuleWarning: Module Warning (from \`replaced original path\`):
9999
Warning
100100
101-
(41:5) <Message>",
101+
(41:5) postcss-plugin: <Message>",
102102
"ModuleWarning: Module Warning (from \`replaced original path\`):
103103
Warning
104104
105-
(6:3) <Message>",
105+
(6:3) postcss-plugin: <Message>",
106106
]
107107
`;
108108
@@ -162,7 +162,7 @@ Array [
162162
"ModuleBuildError: Module build failed (from \`replaced original path\`):
163163
SyntaxError
164164
165-
(1:3) Unnecessary curly bracket
165+
(1:3) /test/fixtures/css/style.css Unnecessary curly bracket
166166
167167
> 1 | a {
168168
| ^

0 commit comments

Comments
 (0)