Skip to content

Commit d6931da

Browse files
committedAug 8, 2018
refactor(Error): add error property checks
1 parent 962b1d6 commit d6931da

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed
 

‎src/Error.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@
99
* @param {Object} err CssSyntaxError
1010
*/
1111
class SyntaxError extends Error {
12-
constructor (err) {
13-
super(err)
12+
constructor (error) {
13+
super(error)
1414

15-
const { line, column, reason } = err
15+
const { line, column, reason } = error
1616

1717
this.name = 'SyntaxError'
1818

19-
this.message = ''
20-
this.message += `${this.name} \n\n(${line}:${column}) ${reason}`
21-
this.message += `\n\n${err.showSourceCode()}\n`
19+
this.message = `${this.name}\n\n`
20+
21+
if (typeof line !== 'undefined') {
22+
this.message += `(${line}:${column}) `
23+
}
24+
25+
this.message += `${reason}`
26+
27+
const code = error.showSourceCode()
28+
29+
if (code) {
30+
this.message += `\n\n${code}\n`
31+
}
2232

2333
this.stack = false
2434
}

‎test/__snapshots__/Errors.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Errors Syntax Error 1`] = `
4-
"SyntaxError
4+
"SyntaxError
55
66
(1:3) Unexpected separator in property
77

0 commit comments

Comments
 (0)
Please sign in to comment.