Skip to content

Commit ae3d8ae

Browse files
fix: use cause for original errors and warnings (#1526)
1 parent c0ce599 commit ae3d8ae

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
@@ -1345,55 +1345,55 @@ function combineRequests(preRequest, url) {
13451345
: preRequest + url;
13461346
}
13471347

1348-
function warningFactory(obj) {
1348+
function warningFactory(warning) {
13491349
let message = "";
13501350

1351-
if (typeof obj.line !== "undefined") {
1352-
message += `(${obj.line}:${obj.column}) `;
1351+
if (typeof warning.line !== "undefined") {
1352+
message += `(${warning.line}:${warning.column}) `;
13531353
}
13541354

1355-
if (typeof obj.plugin !== "undefined") {
1356-
message += `from "${obj.plugin}" plugin: `;
1355+
if (typeof warning.plugin !== "undefined") {
1356+
message += `from "${warning.plugin}" plugin: `;
13571357
}
13581358

1359-
message += obj.text;
1359+
message += warning.text;
13601360

1361-
if (obj.node) {
1362-
message += `\n\nCode:\n ${obj.node.toString()}\n`;
1361+
if (warning.node) {
1362+
message += `\n\nCode:\n ${warning.node.toString()}\n`;
13631363
}
13641364

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

1367-
warning.stack = null;
1367+
obj.stack = null;
13681368

1369-
return warning;
1369+
return obj;
13701370
}
13711371

1372-
function syntaxErrorFactory(obj) {
1372+
function syntaxErrorFactory(error) {
13731373
let message = "\nSyntaxError\n\n";
13741374

1375-
if (typeof obj.line !== "undefined") {
1376-
message += `(${obj.line}:${obj.column}) `;
1375+
if (typeof error.line !== "undefined") {
1376+
message += `(${error.line}:${error.column}) `;
13771377
}
13781378

1379-
if (typeof obj.plugin !== "undefined") {
1380-
message += `from "${obj.plugin}" plugin: `;
1379+
if (typeof error.plugin !== "undefined") {
1380+
message += `from "${error.plugin}" plugin: `;
13811381
}
13821382

1383-
message += obj.file ? `${obj.file} ` : "<css input> ";
1384-
message += `${obj.reason}`;
1383+
message += error.file ? `${error.file} ` : "<css input> ";
1384+
message += `${error.reason}`;
13851385

1386-
const code = obj.showSourceCode();
1386+
const code = error.showSourceCode();
13871387

13881388
if (code) {
13891389
message += `\n\n${code}\n`;
13901390
}
13911391

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

1394-
error.stack = null;
1394+
obj.stack = null;
13951395

1396-
return error;
1396+
return obj;
13971397
}
13981398

13991399
export {

0 commit comments

Comments
 (0)