Skip to content

Commit 0157385

Browse files
bartvenemanBart Veneman
andauthored
Adds checks for error message so that doesnt break (#197)
Co-authored-by: Bart Veneman <bart.veneman@drukwerkdeal.nl>
1 parent 86dd41a commit 0157385

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ module.exports = async css => {
2020

2121
return Promise.resolve(processNodes(rootNode))
2222
} catch (error) {
23-
const {line, column, reason} = error
24-
const message = error.showSourceCode
25-
? `${reason} at line ${line}, column ${column}:\n\n${error.showSourceCode(
26-
false
27-
)}`
28-
: `${reason} at line ${line}, column ${column}:\n\n${error.source}`
23+
const {line, column, reason, source} = error
24+
const message = source && line && reason && column
25+
? `${reason} at line ${line}, column ${column}:\n\n${source}`
26+
: error.message
2927

3028
return Promise.reject(new SyntaxError(message))
3129
}

test/analyzer/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ test('it breaks with invalid CSS', async t => {
55
const cssWithSyntaxError = 'a { color red }'
66
const error = await t.throwsAsync(analyzer(cssWithSyntaxError))
77

8+
t.true(error.message.includes('Unknown word at line 1, column 5:'))
89
t.is(
910
error.message,
10-
'Unknown word at line 1, column 5:\n\n> 1 | a { color red }\n | ^'
11+
'Unknown word at line 1, column 5:\n\na { color red }'
1112
)
1213
})
1314

test/parser/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ test('parser throws a useful error on invalid CSS', async t => {
2929
const cssWithSyntaxError = 'a { color red }'
3030
const error = await t.throwsAsync(parser(cssWithSyntaxError))
3131

32+
t.true(error.message.includes('Unknown word at line 1, column 5:'))
3233
t.is(
3334
error.message,
34-
'Unknown word at line 1, column 5:\n\n> 1 | a { color red }\n | ^'
35+
'Unknown word at line 1, column 5:\n\na { color red }'
3536
)
3637
})

0 commit comments

Comments
 (0)