Closed dilyanpalauzov closed 1 year ago
The problem why there is no stack trace in this case, is that the error occurs in the Java layer of openHAB and only the message of the exception is logged.
To solve this, we have two options:
I‘ prefer the second option, as this would help with debugging in all cases of errors during the script loading, regardless where they occur.
@jpg0 WDYT?
triggers.ItemStateChangeTrigger()
could be extended to accept an Item object as parameter, in addition to string.
@florian-h05 I believe that the policy for the Java layer is that stack traces are not logged, except for unanticipated errors within openHAB, indicating that a core fix is required. @kaikreuzer would be able to confirm this.
Okay, but I am wondering if we could have an exception from this policy here, because the logged message clearly says that it is a script problem (Error during evaluation of script 'file:/etc/openhab/automation/js/zz.js'
) and the stack trace should show that the root cause of the exception is inside the script file.
If we can't, what would be your proposal to avoid such problems? I've also encountered this when I passed the wrong pramater to the Item history classes methods. Introducing type checks for all our wrapper functions is no solution in my opinion.
I‘ve modified the add-on to print the stack trace, but seems like the stack trace doesn‘t help in this case:
I can not find any reference to the script in the stack trace.
So seems like we should add type checks to openhab-js.
Please permit to triggers.ItemStateChangeTrigger()
to accept in addition to string also an Item object.
Please permit to triggers.ItemStateChangeTrigger() to accept in addition to string also an Item object.
Whilst I will add that functionality, I am wondering why you haven't just passed the item name to the trigger instead of the Item (supposing that my_array holds the Items):
rules.JSRule({
triggers: my_array.map(y => triggers.ItemStateChangeTrigger(y.name)),
execute: (data) => {
console.log(data)
}
))
I am wondering why you haven't just passed the item name to the trigger instead of the Item (supposing that my_array holds the Items)
Because I have forgotten that I have to pass strings.
When I create a JS rule as in
and the elements of my_array are Items (not strings), openHAB 3.3 logs:
The error disappears once I pass to triggers.ItemStateChangeTrigger() a string.
The error message 2022-11-24 09:58:11.273 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/js/zz.js': java.lang.IllegalArgumentException: Invalid type '{com.oracle.truffle.polyglot.PolyglotMap}' of configuration value!
is very unclear on the exact problem and its location.
Please extend openhab-js to print in such cases the line and column, where the error occurs, and hint that the problem is wrong type passed to
triggers.ItemStateChangeTrigger()
.