Skip to content

Commit d04b593

Browse files
committed
* (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)
1 parent 0f8e3f0 commit d04b593

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ And then call `npm run build`.
3838

3939
## Changelog
4040

41+
### __WORK IN PROGRESS__
42+
* (Apollon77) Do not try to set a state value if object creation was not successful (Sentry IOBROKER-JAVASCRIPT-5G)
43+
* (Apollon77) Make sure no incorrect states are trying to be set (Sentry IOBROKER-JAVASCRIPT-5F, IOBROKER-JAVASCRIPT-5A)
44+
4145
### 4.10.9 (2021-01-13)
4246
* (Apollon77) Make sure to end all Timeouts
4347
* (Apollon77) Prevent crash case (Sentry IOBROKER-JAVASCRIPT-51)

lib/mirror.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class Mirror {
3131
log: text => console.log(text),
3232
warn: text => console.warn(text),
3333
error: text => console.error(text)
34-
};
35-
34+
};
35+
3636
if (!fs.existsSync(this.diskRoot)) {
3737
try {
3838
fs.mkdirSync(this.diskRoot);
@@ -545,7 +545,11 @@ class Mirror {
545545
native: {}
546546
};
547547
list[folderId] = obj;
548-
this.adapter.setForeignObject(folderId, obj);
548+
try {
549+
this.adapter.setForeignObject(folderId, obj);
550+
} catch (err) {
551+
this.log.warn(`Error while checking script folders for id "${id}": ${err}`);
552+
}
549553
}
550554
}
551555
}

lib/sandbox.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,13 +1916,13 @@ function sandBox(script, name, verbose, debug, context) {
19161916
}, function (err) {
19171917
err && adapter.log.warn('Cannot set object "' + id + '": ' + err);
19181918

1919-
if (initValue !== undefined) {
1919+
if (!err && initValue !== undefined) {
19201920
if (isObject(initValue) && initValue.ack !== undefined) {
19211921
adapter.setForeignState(id, initValue, callback);
19221922
} else {
19231923
adapter.setForeignState(id, initValue, true, callback);
19241924
}
1925-
} else if (!forceCreation) {
1925+
} else if (!err && !forceCreation) {
19261926
adapter.setForeignState(id, null, true, callback);
19271927
} else {
19281928
if (typeof callback === 'function') {

main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,12 @@ function prepareScript(obj, callback) {
16941694
let _name;
16951695
if (obj && obj._id) {
16961696
_name = obj._id;
1697-
adapter.setState('scriptEnabled.' + _name.substring('script.js.'.length), false, true);
1697+
const scriptIdName = _name.substring('script.js.'.length);
1698+
if (scriptIdName.length) {
1699+
adapter.setState('scriptEnabled.' + scriptIdName, false, true);
1700+
} else {
1701+
adapter.log.error('Invalid scriptname');
1702+
}
16981703
}
16991704
!obj && adapter.log.error('Invalid script');
17001705
typeof callback === 'function' && callback(false, _name);

0 commit comments

Comments
 (0)