mirror of
https://github.com/The-Low-Code-Foundation/OpenNoodl.git
synced 2026-01-11 14:52:55 +01:00
Fix: Javascript node error logs (#14)
In some cases the error is a string, and when logging it will write "undefined" into the console instead of providing a useful error message.
This commit is contained in:
committed by
Richard Osborne
parent
908ad18451
commit
62d545d4f9
@@ -1,4 +1,5 @@
|
|||||||
const JavascriptNodeParser = require('../../javascriptnodeparser');
|
const JavascriptNodeParser = require('../../javascriptnodeparser');
|
||||||
|
const { logJavaScriptNodeError } = require('../../utils');
|
||||||
|
|
||||||
const SimpleJavascriptNode = {
|
const SimpleJavascriptNode = {
|
||||||
name: 'JavaScriptFunction',
|
name: 'JavaScriptFunction',
|
||||||
@@ -139,11 +140,8 @@ const SimpleJavascriptNode = {
|
|||||||
JavascriptNodeParser.getComponentScopeForNode(this)
|
JavascriptNodeParser.getComponentScopeForNode(this)
|
||||||
]);
|
]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(
|
logJavaScriptNodeError(e);
|
||||||
'Error in JS node run code.',
|
|
||||||
Object.getPrototypeOf(e).constructor.name + ': ' + e.message,
|
|
||||||
e.stack
|
|
||||||
);
|
|
||||||
if (this.context.editorConnection && this.context.isWarningTypeEnabled('javascriptExecution')) {
|
if (this.context.editorConnection && this.context.isWarningTypeEnabled('javascriptExecution')) {
|
||||||
this.context.editorConnection.sendWarning(
|
this.context.editorConnection.sendWarning(
|
||||||
this.nodeScope.componentOwner.name,
|
this.nodeScope.componentOwner.name,
|
||||||
|
|||||||
@@ -12,6 +12,24 @@ function getAbsoluteUrl(_url) {
|
|||||||
return (Noodl.baseUrl || '/') + url;
|
return (Noodl.baseUrl || '/') + url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log an error thrown by the JavaScript nodes.
|
||||||
|
*
|
||||||
|
* @param {any} error
|
||||||
|
*/
|
||||||
|
function logJavaScriptNodeError(error) {
|
||||||
|
if (typeof error === 'string') {
|
||||||
|
console.log('Error in JS node run code.', error);
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
'Error in JS node run code.',
|
||||||
|
Object.getPrototypeOf(error).constructor.name + ': ' + error.message,
|
||||||
|
error.stack
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAbsoluteUrl
|
getAbsoluteUrl,
|
||||||
|
logJavaScriptNodeError
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Node = require('@noodl/runtime').Node,
|
const Node = require('@noodl/runtime').Node;
|
||||||
JavascriptNodeParser = require('@noodl/runtime/src/javascriptnodeparser');
|
const JavascriptNodeParser = require('@noodl/runtime/src/javascriptnodeparser');
|
||||||
|
const { logJavaScriptNodeError } = require('@noodl/runtime/src/utils');
|
||||||
const guid = require('../../guid');
|
const guid = require('../../guid');
|
||||||
|
|
||||||
/*const defaultCode = "define({\n"+
|
/*const defaultCode = "define({\n"+
|
||||||
@@ -372,7 +372,8 @@ var Javascript = {
|
|||||||
internal.changedInputs
|
internal.changedInputs
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Error in JS node run code.', Object.getPrototypeOf(e).constructor.name + ': ' + e.message);
|
logJavaScriptNodeError(e);
|
||||||
|
|
||||||
if (this.context.editorConnection && this.context.isWarningTypeEnabled('javascriptExecution')) {
|
if (this.context.editorConnection && this.context.isWarningTypeEnabled('javascriptExecution')) {
|
||||||
this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name, this.id, 'js-run-waring', {
|
this.context.editorConnection.sendWarning(this.nodeScope.componentOwner.name, this.id, 'js-run-waring', {
|
||||||
showGlobally: true,
|
showGlobally: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user