diff --git a/README.md b/README.md index b4dd4b2d3..40cdadd7a 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,10 @@ And then call `npm run build`. ## Changelog +### __WORK IN PROGRESS__ +* (Apollon77) Do not try to set a state value if object creation was not successful (Sentry IOBROKER-JAVASCRIPT-5G) +* (Apollon77) Make sure no incorrect states are trying to be set (Sentry IOBROKER-JAVASCRIPT-5F, IOBROKER-JAVASCRIPT-5A) + ### 4.10.9 (2021-01-13) * (Apollon77) Make sure to end all Timeouts * (Apollon77) Prevent crash case (Sentry IOBROKER-JAVASCRIPT-51) diff --git a/lib/mirror.js b/lib/mirror.js index 079846ec9..e9e3e2f26 100644 --- a/lib/mirror.js +++ b/lib/mirror.js @@ -31,8 +31,8 @@ class Mirror { log: text => console.log(text), warn: text => console.warn(text), error: text => console.error(text) - }; - + }; + if (!fs.existsSync(this.diskRoot)) { try { fs.mkdirSync(this.diskRoot); @@ -545,7 +545,11 @@ class Mirror { native: {} }; list[folderId] = obj; - this.adapter.setForeignObject(folderId, obj); + try { + this.adapter.setForeignObject(folderId, obj); + } catch (err) { + this.log.warn(`Error while checking script folders for id "${id}": ${err}`); + } } } } diff --git a/lib/sandbox.js b/lib/sandbox.js index a00bce2fe..df47423d9 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -1916,13 +1916,13 @@ function sandBox(script, name, verbose, debug, context) { }, function (err) { err && adapter.log.warn('Cannot set object "' + id + '": ' + err); - if (initValue !== undefined) { + if (!err && initValue !== undefined) { if (isObject(initValue) && initValue.ack !== undefined) { adapter.setForeignState(id, initValue, callback); } else { adapter.setForeignState(id, initValue, true, callback); } - } else if (!forceCreation) { + } else if (!err && !forceCreation) { adapter.setForeignState(id, null, true, callback); } else { if (typeof callback === 'function') { diff --git a/main.js b/main.js index 81e398b02..d8c912a97 100644 --- a/main.js +++ b/main.js @@ -1694,7 +1694,12 @@ function prepareScript(obj, callback) { let _name; if (obj && obj._id) { _name = obj._id; - adapter.setState('scriptEnabled.' + _name.substring('script.js.'.length), false, true); + const scriptIdName = _name.substring('script.js.'.length); + if (scriptIdName.length) { + adapter.setState('scriptEnabled.' + scriptIdName, false, true); + } else { + adapter.log.error('Invalid scriptname'); + } } !obj && adapter.log.error('Invalid script'); typeof callback === 'function' && callback(false, _name);