-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to catch errors when scss parsing fails #539
Comments
notlee
changed the title
Unable to catch errors from scss-comment-parser
Unable to catch errors when scss parsing fails
Aug 12, 2019
Here's a diff which I think would solve the problem. diff --git a/src/parser.js b/src/parser.js
index c00d04b..ceb71f8 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -60,8 +60,6 @@ export default class Parser {
let data = []
let transform = (file, enc, cb) => {
- // Pass-through.
- cb(null, file)
let parseFile = ({ buf, name, path }) => {
let fileData = this.parse(buf.toString(enc), name)
@@ -76,21 +74,27 @@ export default class Parser {
})
}
- if (file.isBuffer()) {
- let args = {
- buf: file.contents,
- name: path.basename(file.relative),
- path: file.relative,
+ try {
+ if (file.isBuffer()) {
+ let args = {
+ buf: file.contents,
+ name: path.basename(file.relative),
+ path: file.relative,
+ }
+ parseFile(args)
}
- parseFile(args)
+ if (file.isStream()) {
+ file.pipe(concat(buf => {
+ parseFile({ buf })
+ }))
+ }
+ } catch (error) {
+ cb(error);
}
- if (file.isStream()) {
- file.pipe(concat(buf => {
- parseFile({ buf })
- }))
- }
+ // Pass-through.
+ cb(null, file)
}
let flush = cb => { |
Hi @notlee, yes, that seems like reasonable addition ;) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't appear to be possible to catch a scss parsing error.
E.g. given this scss file which will currently cause a parse error:
sassdoc will cause an error which cannot be caught in a try/catch block:
I believe this may be because the error is from a stream, and the
through
callback isn't called around here?The text was updated successfully, but these errors were encountered: