Skip to content

fix: warnings and errors serialization #1142

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

Merged
merged 1 commit into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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