Skip to content

Commit d4f2335

Browse files
refactor: error and warning message
1 parent 0239e9f commit d4f2335

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/Error.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path';
12
/**
23
* **PostCSS Syntax Error**
34
*
@@ -9,7 +10,7 @@
910
* @param {Object} err CssSyntaxError
1011
*/
1112
class SyntaxError extends Error {
12-
constructor(error) {
13+
constructor(error, rootContext) {
1314
super(error);
1415

1516
const { line, column, reason, plugin, file } = error;
@@ -23,8 +24,10 @@ class SyntaxError extends Error {
2324
}
2425

2526
this.message += plugin ? `${plugin}: ` : '';
26-
this.message += file || '<css input>';
27-
this.message += ` ${reason}`;
27+
this.message += file
28+
? `${path.relative(rootContext, file)} `
29+
: '<css input> ';
30+
this.message += `${reason}`;
2831

2932
const code = error.showSourceCode();
3033

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default async function loader(content, sourceMap, meta) {
108108
}
109109

110110
if (error.name === 'CssSyntaxError') {
111-
callback(new SyntaxError(error));
111+
callback(new SyntaxError(error, this.rootContext));
112112
} else {
113113
callback(error);
114114
}

test/__snapshots__/loader.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ Array [
162162
"ModuleBuildError: Module build failed (from \`replaced original path\`):
163163
SyntaxError
164164
165-
(1:3) /test/fixtures/css/style.css Unnecessary curly bracket
165+
(1:3) css/style.css Unnecessary curly bracket
166166
167167
> 1 | a {
168168
| ^

0 commit comments

Comments
 (0)