Skip to content

Commit 91b33eb

Browse files
committed
* (Apollon77) Optimize error handling in createState and file mirror again
1 parent 392d371 commit 91b33eb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

README.md

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

3939
## Changelog
4040

41+
### __WORK IN PROGRESS__
42+
* (Apollon77) Optimize error handling in createState and file mirror again
43+
4144
### 4.10.10 (2021-01-22)
4245
* (Apollon77) Do not try to set a state value if object creation was not successful (Sentry IOBROKER-JAVASCRIPT-5G)
4346
* (Apollon77) Make sure no incorrect states are trying to be set (Sentry IOBROKER-JAVASCRIPT-5F, IOBROKER-JAVASCRIPT-5A)

lib/mirror.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ class Mirror {
546546
};
547547
list[folderId] = obj;
548548
try {
549-
this.adapter.setForeignObject(folderId, obj);
549+
this.adapter.setForeignObject(folderId, obj, err => this.log.warn(`Error while checking script folders for id "${id}": ${err}`));
550550
} catch (err) {
551551
this.log.warn(`Error while checking script folders for id "${id}": ${err}`);
552552
}

lib/sandbox.js

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

1919-
if (!err && initValue !== undefined) {
1919+
if (err) {
1920+
if (typeof callback === 'function') {
1921+
try {
1922+
callback.call(sandbox, err);
1923+
} catch (e) {
1924+
errorInCallback(e); //adapter.log.error('Error in callback: ' + e)
1925+
}
1926+
}
1927+
} else if (initValue !== undefined) {
19201928
if (isObject(initValue) && initValue.ack !== undefined) {
19211929
adapter.setForeignState(id, initValue, callback);
19221930
} else {
19231931
adapter.setForeignState(id, initValue, true, callback);
19241932
}
1925-
} else if (!err && !forceCreation) {
1933+
} else if (!forceCreation) {
19261934
adapter.setForeignState(id, null, true, callback);
19271935
} else {
19281936
if (typeof callback === 'function') {

0 commit comments

Comments
 (0)