Skip to content

Commit

Permalink
fix: handling error better
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed May 25, 2023
1 parent 21caa3e commit d5ad7a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ import LessError from "./LessError";
async function lessLoader(source) {
const options = this.getOptions(schema);
const callback = this.async();
const implementation = getLessImplementation(this, options.implementation);
let implementation;

try {
implementation = getLessImplementation(this, options.implementation);
} catch (error) {
callback(error);

return;
}

if (!implementation) {
callback(
Expand Down
11 changes: 2 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,8 @@ function getLessImplementation(loaderContext, implementation) {
if (!implementation || typeof implementation === "string") {
const lessImplPkg = implementation || "less";

try {
// eslint-disable-next-line import/no-dynamic-require, global-require
resolvedImplementation = require(lessImplPkg);
} catch (error) {
loaderContext.emitError(error);

// eslint-disable-next-line consistent-return
return;
}
// eslint-disable-next-line import/no-dynamic-require, global-require
resolvedImplementation = require(lessImplPkg);
}

// eslint-disable-next-line consistent-return
Expand Down

0 comments on commit d5ad7a9

Please sign in to comment.