Skip to content

Commit

Permalink
fix: error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Sep 22, 2020
1 parent 538f4ba commit 3233f86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/evaluator.js
Expand Up @@ -74,7 +74,15 @@ async function getDependencies(
nodes.filename = filepath;

const parser = new Parser(code, options);
const ast = parser.parse();

let ast;

try {
ast = parser.parse();
} catch (error) {
loaderContext.emitError(error);
}

const deps = new Map();

class ImportVisitor extends DepsResolver {
Expand Down
17 changes: 12 additions & 5 deletions src/index.js
Expand Up @@ -96,8 +96,13 @@ export default async function stylusLoader(source) {
// let stylus do its magic
styl.render(async (error, css) => {
if (error) {
this.addDependency(path.normalize(error.filename));
return callback(error);
if (error.filename) {
this.addDependency(path.normalize(error.filename));
}

callback(error);

return;
}

// eslint-disable-next-line no-underscore-dangle
Expand All @@ -119,11 +124,13 @@ export default async function stylusLoader(source) {
(await readFile(this.fs, file)).toString()
)
);
} catch (errorFs) {
return callback(errorFs);
} catch (fsError) {
callback(fsError);

return;
}
}

return callback(null, css, map);
callback(null, css, map);
});
}

0 comments on commit 3233f86

Please sign in to comment.