From 103619741dcb02a7e00cad758241b33bc19cbc92 Mon Sep 17 00:00:00 2001 From: Florian Hotze Date: Sun, 20 Nov 2022 20:30:42 +0100 Subject: [PATCH] [jsscripting] Fix the `console.trace` polyfill to log a stack trace & Stringify JS `Error` (#13749) * [jsscripting] Fix the `console.trace` polyfill to log a stack trace & Stringify JS `Error` * [jsscripting] Add myself to the codeowners Fixes #12646 Signed-off-by: Florian Hotze --- CODEOWNERS | 2 +- .../node_modules/@jsscripting-globals.js | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 34634bf4910..a4a46bfa260 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -7,7 +7,7 @@ # Add-on maintainers: /bundles/org.openhab.automation.groovyscripting/ @wborn /bundles/org.openhab.automation.jrubyscripting/ @boc-tothefuture -/bundles/org.openhab.automation.jsscripting/ @jpg0 +/bundles/org.openhab.automation.jsscripting/ @jpg0 @florian-h05 /bundles/org.openhab.automation.jythonscripting/ @openhab/add-ons-maintainers /bundles/org.openhab.automation.pidcontroller/ @fwolter /bundles/org.openhab.automation.pwm/ @fwolter diff --git a/bundles/org.openhab.automation.jsscripting/src/main/resources/node_modules/@jsscripting-globals.js b/bundles/org.openhab.automation.jsscripting/src/main/resources/node_modules/@jsscripting-globals.js index a398547833f..b68f05ebc91 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/resources/node_modules/@jsscripting-globals.js +++ b/bundles/org.openhab.automation.jsscripting/src/main/resources/node_modules/@jsscripting-globals.js @@ -19,7 +19,7 @@ function stringify (value) { try { - if (Java.isJavaObject(value)) { + if (Java.isJavaObject(value) || value instanceof Error) { return value.toString(); } else { // special cases @@ -129,20 +129,8 @@ log.error(format.apply(null, arguments)); }, - trace: function (e) { - if (Java.isJavaObject(e)) { - log.trace(e.getLocalizedMessage(), e); - } else { - if (e.stack) { - log.trace(e.stack); - } else { - if (e.message) { - log.trace(format.apply(null, [(e.name || 'Error') + ':', e.message])); - } else { - log.trace((e.name || 'Error')); - } - } - } + trace: function () { + log.trace(new Error(format.apply(null, arguments)).stack.replace(/^Error: /, '')); }, time: function (label) {