-
Notifications
You must be signed in to change notification settings - Fork 2
Can't get it to work #8
Comments
Thanks for giving it a try! The missing import you are seeing is because those modules are imported from the host jar, and I suspect the one you have is too old. Either you can build it yourself from https://github.com/jpg0/openhab-graaljs or I can do it and put it somewhere when I get a chance to? |
Thanks for the quick feedback!
I can try it, though I am not a Java guy myself, so will probably need much longer than you. In case you have the time, a ready to use build would certainly be much appreciated! :) Btw, the repo, is this the work that is supposed to eventually get merged into core, or are you following a different approach (user-land binding?) now? I saw that the PR was stuck for quite a while unfortunately... |
Ok, I've built a release - please give it a try! Regarding merging to core; whilst I'm not an OH maintainer, they are keen for the Java part to become the primary JS engine used, as Nashorn is deprecated now. I do plan to get it merged in (either to core or the bundled plugins), but haven't had the time recently to create all the PRs. As for the JS libs (this repo), this is less clear, although this is far ahead of anything else, so even if it were not directly this code I would expect it to be close. The JS libs that are available for Nashorn are pretty terrible. |
Thanks a lot! I just did, but requirig modules seems to not work anymore (which worked before!):
I have |
I have an idea of what the problem is here: the changes in the build you are now using are quite major from the older one, the primary one being that I swapped out my own module loading with the one that comes with GraalJS. It works a little differently, and there is less flexibility on the paths that it will look in to find modules (it strictly follows the nodejs convention). I had to rearrange my JS folders to get it to work but I have all my code online, so you can see how I have laid things out: https://github.com/jpg0/oh-config |
Thanks, that got me a little bit further. I did a Idk why, but now when I have same obvious syntax error, or just
Apart from that, as I said I get no exception anymore when there is no obvious error anymore. But also I don't see anything happen. Even a simple attempt to log something does not show up. E.g. for this script, I would expect to see some logging, right?
I do see a message |
So I'm not sure why your code (or mine) is not working, but you can increase the logging by setting the following namespaces to debug:
(do this however you like, but I do it by going into the OH shell with The first namespace should mean that any exceptions from JS code get stacks in the log. The second enables debug logging for the JS code. I'm not sure what the default is, but it may be Give it a go and let me know if you get any further. |
I tried it with these logging settings, but did not get much further... So under the However at least I found something: instantiating a logger already throws that exception, and it seems to be related to this So when I have this code, this already throws:
But when I provide
... then I at least don't see an exception anymore. But I do get one when trying to actually log anything ( Are you using the same .jar as the one I am using? (from https://github.com/jpg0/openhab-graaljs/releases/tag/v1.0) |
TBH I have had some issues with the log.js module, but the ones I've seen have been related to parsing stack frames. It's something that I ported from elsewhere which really needs a rewrite. The appenders thing was something that I added to allow consumers to insert log appenders in Javascript in case they want their log lines to get sent somewhere else in addition to the OH log. I use it to send any ERROR lines to Telegram so that I don't miss any errors. The way I came up with to do this was to depend on a module with a specific name ( Anyway, let's figure out where the issue is. First, we should isolate the problem to either the host GraalJS bundle, or the ohj library. I'd advise doing this by logging something directly, without using ohj. You can do this with a script containing:
If this fails, then I believe the problem is with the bundle. If not, it is likely with ohj (and the log module). Also, I am not using that exact jar (I built it after you asked), but have one that should reflect the same code that I built a long time ago (although didn't post it as I wasn't sure exactly how to extract it from OH). If it has problems though I'll switch to it to get it working. Since you've started trying to get it working, it's inspired me to find the time to make progress on reintegrating back in OH, which will mean that I need to make changes and rebuild + retest this bundle anyway openhab/openhab-addons#8441. |
It did not fail, I was able to see this in OH logs! |
Investigated this a bit more, and finally got at least the logger working:
|
Again, this was pretty hard to debug, as again I don't see anything but that |
After having figured out #12, I finally have a dummy rule getting triggered successfully! 🚀 Thanks so far for your assistance here! I'm going to close this, as the issue is kind-of solved, and we have the more specific ones to track the remaining issues! |
BTW, regarding the nightmare debugging - yes I completely agree. I explicitly included code in the bundle to log the JS stack, although there is some contention in OH core about whether this will even be allowed (!). They only want stack traces for errors in the core OH logic, and it's questionable whether scripts qualify for that. This is why I've logged it with a specially named (and by default disabled) appender of |
Hey, first thanks for working on this! Really looking forward to be able to write rules in modern JavaScript! 😁
Unfortunately I am struggling to get this to work. I tried first with how it is described in the Readme, but get this error with a simple test rule upon requiring
ohj
:Seems this is caused by
ohj/fluent/fluent.js
Line 1 in 6ccf04a
../log
)I am able to require from other modules like
lodash
without any errors in the log. So at least the GraalVM integration seems to work.I then realized the published version on npm is quite outdated, so I tried the current master branch (copying the repo into
/conf/automation/lib/javascript/community/ohj
and installing deps). But then I get this one:Not really following how these special (non-existing)
@runtime
modules are supposed to work?I am using the jar linked from the Readme, with Openhab 2.5.6.
The text was updated successfully, but these errors were encountered: