Skip to content

Commit e8873f4

Browse files
fix: use cause to keep original errors and warnings (#655)
1 parent 7e5eaeb commit e8873f4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/utils.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -559,55 +559,55 @@ function reportError(loaderContext, callback, error) {
559559
}
560560
}
561561

562-
function warningFactory(obj) {
562+
function warningFactory(warning) {
563563
let message = "";
564564

565-
if (typeof obj.line !== "undefined") {
566-
message += `(${obj.line}:${obj.column}) `;
565+
if (typeof warning.line !== "undefined") {
566+
message += `(${warning.line}:${warning.column}) `;
567567
}
568568

569-
if (typeof obj.plugin !== "undefined") {
570-
message += `from "${obj.plugin}" plugin: `;
569+
if (typeof warning.plugin !== "undefined") {
570+
message += `from "${warning.plugin}" plugin: `;
571571
}
572572

573-
message += obj.text;
573+
message += warning.text;
574574

575-
if (obj.node) {
576-
message += `\n\nCode:\n ${obj.node.toString()}\n`;
575+
if (warning.node) {
576+
message += `\n\nCode:\n ${warning.node.toString()}\n`;
577577
}
578578

579-
const warning = new Error(message);
579+
const obj = new Error(message, { cause: warning });
580580

581-
warning.stack = null;
581+
obj.stack = null;
582582

583-
return warning;
583+
return obj;
584584
}
585585

586-
function syntaxErrorFactory(obj) {
586+
function syntaxErrorFactory(error) {
587587
let message = "\nSyntaxError\n\n";
588588

589-
if (typeof obj.line !== "undefined") {
590-
message += `(${obj.line}:${obj.column}) `;
589+
if (typeof error.line !== "undefined") {
590+
message += `(${error.line}:${error.column}) `;
591591
}
592592

593-
if (typeof obj.plugin !== "undefined") {
594-
message += `from "${obj.plugin}" plugin: `;
593+
if (typeof error.plugin !== "undefined") {
594+
message += `from "${error.plugin}" plugin: `;
595595
}
596596

597-
message += obj.file ? `${obj.file} ` : "<css input> ";
598-
message += `${obj.reason}`;
597+
message += error.file ? `${error.file} ` : "<css input> ";
598+
message += `${error.reason}`;
599599

600-
const code = obj.showSourceCode();
600+
const code = error.showSourceCode();
601601

602602
if (code) {
603603
message += `\n\n${code}\n`;
604604
}
605605

606-
const error = new Error(message);
606+
const obj = new Error(message, { cause: error });
607607

608-
error.stack = null;
608+
obj.stack = null;
609609

610-
return error;
610+
return obj;
611611
}
612612

613613
export {

0 commit comments

Comments
 (0)