-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
LessError.js
39 lines (30 loc) · 877 Bytes
/
LessError.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import path from "path";
class LessError extends Error {
constructor(error) {
super();
this.message = [
"\n",
...LessError.getFileExcerptIfPossible(error),
error.message.charAt(0).toUpperCase() + error.message.slice(1),
error.filename
? ` Error in ${path.normalize(error.filename)} (line ${
error.line
}, column ${error.column})`
: "",
].join("\n");
this.hideStack = true;
}
static getFileExcerptIfPossible(lessError) {
if (typeof lessError.extract === "undefined") {
return [];
}
const excerpt = lessError.extract.slice(0, 2);
const column = Math.max(lessError.column - 1, 0);
if (typeof excerpt[0] === "undefined") {
excerpt.shift();
}
excerpt.push(`${new Array(column).join(" ")}^`);
return excerpt;
}
}
export default LessError;