-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.js
54 lines (44 loc) · 1.11 KB
/
error.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const re = /^\s*(.*)\[(\d*),\s(\d*)\]\s*-\s(.*)/i;
String.prototype.format = function() {
return [...arguments].reduce((p, c) => p.replace(/%s/, c), this);
};
class Error {
/**
* @param {string} line
*/
constructor(line) {
this.parseError(line);
}
/**
*
* @param {string} line
*/
parseError(line) {
var found = line.match(re);
if (found !== null) {
this.file = found[1];
this.line = found[2];
this.position = found[3];
this.error = found[4];
this.valid = true;
}
}
isValid() {
return this.valid;
}
getClassname() {
return this.file.replace('src/', '').replace(new RegExp('#', 'g'), '/');
}
getName() {
return "%s [Line: %s / Position: %s]: %s".format(this.getClassname(), this.line, this.position, this.error);
}
toString() {
return "file: %s\nline: %s\nposition: %s\nerror: %s".format(
this.file,
this.line,
this.position,
this.error
);
}
}
module.exports = Error;