Skip to content

Commit ed6f313

Browse files
fix: warnings and errors serialization (#1142)
1 parent 1f99474 commit ed6f313

File tree

5 files changed

+70
-100
lines changed

5 files changed

+70
-100
lines changed

src/SassError.js

-32
This file was deleted.

src/SassWarning.js

-17
This file was deleted.

src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
getModernWebpackImporter,
1010
getCompileFn,
1111
normalizeSourceMap,
12+
errorFactory,
1213
} from "./utils";
13-
import SassError from "./SassError";
1414

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

90-
callback(new SassError(error));
90+
callback(errorFactory(error));
9191

9292
return;
9393
}

src/utils.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import path from "path";
44
import { klona } from "klona/full";
55
import async from "neo-async";
66

7-
import SassWarning from "./SassWarning";
8-
97
function getDefaultSassImplementation() {
108
let sassImplPkg = "sass";
119

@@ -169,9 +167,12 @@ async function getSassOptions(
169167
}
170168

171169
if (needEmitWarning) {
172-
loaderContext.emitWarning(
173-
new SassWarning(builtMessage, loggerOptions)
174-
);
170+
const warning = new Error(builtMessage);
171+
172+
warning.name = "SassWarning";
173+
warning.stack = null;
174+
175+
loaderContext.emitWarning(warning);
175176
} else {
176177
logger.warn(builtMessage);
177178
}
@@ -781,6 +782,23 @@ function normalizeSourceMap(map, rootContext) {
781782
return newMap;
782783
}
783784

785+
function errorFactory(error) {
786+
let message;
787+
788+
if (error.formatted) {
789+
message = error.formatted.replace(/^Error: /, "");
790+
} else {
791+
// Keep original error if `sassError.formatted` is unavailable
792+
({ message } = error);
793+
}
794+
795+
const obj = new Error(message, { cause: error });
796+
797+
obj.stack = null;
798+
799+
return obj;
800+
}
801+
784802
export {
785803
getSassImplementation,
786804
getSassOptions,
@@ -790,4 +808,5 @@ export {
790808
getCompileFn,
791809
normalizeSourceMap,
792810
isSupportedFibers,
811+
errorFactory,
793812
};

0 commit comments

Comments
 (0)