Skip to content

Commit

Permalink
fix: warnings and errors serialization (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait authored May 28, 2023
1 parent 1f99474 commit ed6f313
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 100 deletions.
32 changes: 0 additions & 32 deletions src/SassError.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/SassWarning.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
getModernWebpackImporter,
getCompileFn,
normalizeSourceMap,
errorFactory,
} from "./utils";
import SassError from "./SassError";

/**
* The sass-loader makes node-sass and dart-sass available to webpack modules.
Expand Down Expand Up @@ -87,7 +87,7 @@ async function loader(content) {
this.addDependency(path.normalize(error.file));
}

callback(new SassError(error));
callback(errorFactory(error));

return;
}
Expand Down
29 changes: 24 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import path from "path";
import { klona } from "klona/full";
import async from "neo-async";

import SassWarning from "./SassWarning";

function getDefaultSassImplementation() {
let sassImplPkg = "sass";

Expand Down Expand Up @@ -169,9 +167,12 @@ async function getSassOptions(
}

if (needEmitWarning) {
loaderContext.emitWarning(
new SassWarning(builtMessage, loggerOptions)
);
const warning = new Error(builtMessage);

warning.name = "SassWarning";
warning.stack = null;

loaderContext.emitWarning(warning);
} else {
logger.warn(builtMessage);
}
Expand Down Expand Up @@ -781,6 +782,23 @@ function normalizeSourceMap(map, rootContext) {
return newMap;
}

function errorFactory(error) {
let message;

if (error.formatted) {
message = error.formatted.replace(/^Error: /, "");
} else {
// Keep original error if `sassError.formatted` is unavailable
({ message } = error);
}

const obj = new Error(message, { cause: error });

obj.stack = null;

return obj;
}

export {
getSassImplementation,
getSassOptions,
Expand All @@ -790,4 +808,5 @@ export {
getCompileFn,
normalizeSourceMap,
isSupportedFibers,
errorFactory,
};
Loading

0 comments on commit ed6f313

Please sign in to comment.