ioBroker.js-controller
ioBroker.js-controller copied to clipboard
JS controller cannot handle missing ALIAS data points
No existing issues.
- [X] There is no existing issue for my problem.
Description
JS controller crashes if ALIAS datapoint not exists
Reproduction instruction
this.setForeignState("alias.0.example", "test", false);
2024-02-09 12:52:34.543 - [32minfo[39m: admin.0 (807529) Repository received successfully.
2024-02-09 12:52:34.700 - [32minfo[39m: hiob.0 (807565) starting. Version 0.0.54 in /home/pi/ioBroker.hiob/.dev-server/default/node_modules/iobroker.hiob, node: v18.19.0, js-controller: 5.0.19
2024-02-09 12:52:34.825 - [33mwarn[39m: hiob.0 (807565) Alias alias.0.example has no target 5
2024-02-09 12:52:34.830 - [31merror[39m: hiob.0 (807565) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
2024-02-09 12:52:34.833 - [31merror[39m: hiob.0 (807565) unhandled promise rejection: Alias alias.0.example has no target
2024-02-09 12:52:34.838 - [31merror[39m: hiob.0 (807565) Error: Alias alias.0.example has no target
at Object.maybeCallbackWithError (/home/pi/ioBroker.hiob/.dev-server/default/node_modules/@iobroker/js-controller-common/build/lib/common/maybeCallback.js:35:17)
at SamartHomeHandyBis.setForeignState (/home/pi/ioBroker.hiob/.dev-server/default/node_modules/@iobroker/js-controller-adapter/build/lib/adapter/adapter.js:6208:57)
2024-02-09 12:52:34.839 - [31merror[39m: hiob.0 (807565) Alias alias.0.example has no target
2024-02-09 12:52:34.875 - [32minfo[39m: hiob.0 (807565) terminating
2024-02-09 12:52:34.866 - [34mdebug[39m: host.dev-hiob-debmatic Incoming Host message addNotification
const state = await this.getForeignStateAsync("alias.0.example");
2024-02-09 13:25:59.293 - [32minfo[39m: hiob.0 (809499) starting. Version 0.0.54 in /home/pi/ioBroker.hiob/.dev-server/default/node_modules/iobroker.hiob, node: v18.19.0, js-controller: 5.0.19
2024-02-09 13:25:59.334 - [33mwarn[39m: hiob.0 (809499) Alias alias.0.example has no target 8
2024-02-09 13:25:59.339 - [31merror[39m: hiob.0 (809499) Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
2024-02-09 13:25:59.341 - [31merror[39m: hiob.0 (809499) unhandled promise rejection: Alias alias.0.example has no target
2024-02-09 13:25:59.344 - [31merror[39m: hiob.0 (809499) Error: Alias alias.0.example has no target
at Object.maybeCallbackWithError (/home/pi/ioBroker.hiob/.dev-server/default/node_modules/@iobroker/js-controller-common/build/lib/common/maybeCallback.js:35:17)
at SamartHomeHandyBis._getForeignState (/home/pi/ioBroker.hiob/.dev-server/default/node_modules/@iobroker/js-controller-adapter/build/lib/adapter/adapter.js:6469:53)
2024-02-09 13:25:59.345 - [31merror[39m: hiob.0 (809499) Alias alias.0.example has no target
2024-02-09 13:25:59.349 - [34mdebug[39m: host.dev-hiob-debmatic Incoming Host message addNotification
2024-02-09 13:25:59.351 - [32minfo[39m: hiob.0 (809499) terminating
2024-02-09 13:25:59.353 - [33mwarn[39m: hiob.0 (809499) Terminated (UNCAUGHT_EXCEPTION): Without reason
2024-02-09 13:25:59.858 - [32minfo[39m: hiob.0 (809499) terminating
Hm ... how does the object is defined you access here because it has no target defined (which is needed in alias) and thats why the get/setState calls throw an exception in your adapter whcih is not catched - thats why yopur adapter crashes. The js-controller runs correctly
Ok @foxriver76 for "get" we might return null like "state noch defined" in such case ... no idea what we could do on set?
Edit: ah it is a non promise method without callback so this throws yeah.
Ok @foxriver76 for "get" we might return null like "state noch defined" in such case ... no idea what we could do on set?
Just catch in adapter. I am not sure if we need to fix every possible case where an adapter dev not handling possible issues.
For convenience we could return null on exception nd log for get and log for set ... Problem is that then each adapter that uses "Foreign" methods need to check that 100% because someone else could have "fucked up alias objects" :-(
Und ja sollten vllt den "no target" error noch die zugegriffene ID vrpassen das man es erkennt welchesObjekt es ist
Bei jedem Datenpunkt der nicht existiert kommt ein
2024-02-09 12:53:40.205 - [33mwarn[39m: hiob.0 (807681) State "0_userdata.0.example" has no existing object, this might lead to an error in future versions
Und bei fehlenden alias Datenpunkte kommt ein crash....Der js.controller kann mit fehleden alias nicht umgehen.
Please change title to something meankngful. Theres NO crash of js-controller.
Set/get Object raises an exception wich causes to crash the adapter as it does not gandle them.
Issue could be used to discussxwetherbadapter cor should catch all suchcexceptions an log them. But the current title is defenitly misleading
Umgehen schon aber er gibt einen Fehler zurück weil er den Befehl nicht ausführen kann, da alias der ins leere linkt -> State wird nicht geschrieben und das wird mitgeteilt.
Korrekt: ` const state = await this.getForeignStateAsync("0_userdata.0.example");
if (state) {
this.log.info("Geht")
} else {
this.log.info("Geht nicht")
}`
Falsch: ` const state = await this.getForeignStateAsync("alias.0.example");
crash Adapter Neustart
if (state) {
this.log.info("Geht")
} else {
this.log.info("Geht nicht")
}`
Folglich kann js nicht mit fehlenden alias umgehen aber mit allen anderen.
Für get mag das Sinn machen wie Ingo sagt convenience null Objekt aber für set nicht
@foxriver76 Extended case here ... The object in alias.0 which is accessed do not even exists at all!! So we should react the same as we do for "non existing set/getState"? ;-)
Which means warning that we might throw in the future, not really hurting doing it already for these cases as it is done for quite a while now and this is the first case reported. So not sure tbh to take away every possible handling from the adapters themselves, while we have the big target to throw at some point anyway, this just tells do not care about error handling on setState as controller catches it.
In my oppinion behavior getting alias.o.xxx should be identical of getting adapter.0.xxx