Skip to content
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

fix: use cause for original errors and warnings #1526

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 22 additions & 22 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1345,55 +1345,55 @@
: preRequest + url;
}

function warningFactory(obj) {
function warningFactory(warning) {
let message = "";

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

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

message += obj.text;
message += warning.text;

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

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

warning.stack = null;
obj.stack = null;

return warning;
return obj;
}

function syntaxErrorFactory(obj) {
function syntaxErrorFactory(error) {
let message = "\nSyntaxError\n\n";

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

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

Check warning on line 1380 in src/utils.js

View check run for this annotation

Codecov / codecov/patch

src/utils.js#L1380

Added line #L1380 was not covered by tests
}

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

const code = obj.showSourceCode();
const code = error.showSourceCode();

if (code) {
message += `\n\n${code}\n`;
}

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

error.stack = null;
obj.stack = null;

return error;
return obj;
}

export {
Expand Down