Exception handling for bindings

So I’ve been doing some binding development, and you know, it’s just possible I’ve made a mistake or two. I accidentally introduced a NullPointerException with one of my changes. Surprisingly, I didn’t find anything in openhab.log. I kept waiting for some output or error from the binding to appear, but there was nothing. It seems the error message was written to the OH process’s stderr. My OH is started by systemd so it was captured and I found it with journalctl:

Jan 03 01:47:23 xxx karaf[428443]: Exception in thread "OH-binding-powermax:serial:alarm-reader" java.lang.NullPointerException
Jan 03 01:47:23 xxx karaf[428443]:         at org.openhab.binding.powermax.internal.handler.PowermaxBridgeHandler.onNewStateEvent(PowermaxBridgeHandler.java:444)
Jan 03 01:47:23 xxx karaf[428443]:         at org.openhab.binding.powermax.internal.message.PowermaxCommManager.onNewMessageEvent(PowermaxCommManager.java:277)
Jan 03 01:47:23 xxx karaf[428443]:         at org.openhab.binding.powermax.internal.connector.PowermaxConnector.handleIncomingMessage(PowermaxConnector.java:105)
Jan 03 01:47:23 xxx karaf[428443]:         at org.openhab.binding.powermax.internal.connector.PowermaxReaderThread.run(PowermaxReaderThread.java:106)

So my question is: why is this NOT in openhab.log? I’d sort of expect there to be a global exception handler for bindings that logs these exceptions in the same way as other log messages. (This is with OH 3.0.0.)

I don’t know why this is not logged. Maybe something to look into. In general it’s recommended to implement your own catch to RuntimeException in your own threads and see if the binding can recover from it or at least set the state of the thing to offline based to an error state. So the user knows something is wrong.

Thanks, I see the reader thread has a couple of other exception handlers but not a catch-all, and it doesn’t set the thing offline which is a nice idea. I’ll create an issue for this and discuss with @Lolodomo.

Edit: [powermax] Add a catch-all exception handler · Issue #9688 · openhab/openhab-addons · GitHub

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.