From 6076fd5ebb0cd27acdcbd3ea32f6a093c422c7c0 Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Sun, 28 May 2023 04:24:39 +0300 Subject: [PATCH] fix: use `cause` to keep original errors and warnings --- src/utils.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/utils.js b/src/utils.js index 0c7423bb..01b53339 100644 --- a/src/utils.js +++ b/src/utils.js @@ -559,55 +559,55 @@ function reportError(loaderContext, callback, error) { } } -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: `; } - message += obj.file ? `${obj.file} ` : " "; - message += `${obj.reason}`; + message += error.file ? `${error.file} ` : " "; + 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 {