Skip to content

Commit

Permalink
* (Apollon77) Do not try to set a state value if object creation was …
Browse files Browse the repository at this point in the history
…not successful (Sentry IOBROKER-JAVASCRIPT-5G)

* (Apollon77) Make sure no incorrect states are trying to be set (Sentry IOBROKER-JAVASCRIPT-5F, IOBROKER-JAVASCRIPT-5A)
  • Loading branch information
Apollon77 committed Jan 21, 2021
1 parent 0f8e3f0 commit d04b593
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions lib/mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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}`);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
7 changes: 6 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d04b593

Please sign in to comment.