Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing rules, items, and actions fail #15

Closed
rkoshak opened this issue Dec 1, 2021 · 12 comments
Closed

Importing rules, items, and actions fail #15

rkoshak opened this issue Dec 1, 2021 · 12 comments

Comments

@rkoshak
Copy link
Contributor

rkoshak commented Dec 1, 2021

I'm running the snapshot of OH from Monday and I've installed the helper library using npm following the instructions in the readme. I've included at the top of my script per the readme

const {rules, items, things, log, triggers, actions, metadata, osgi} = require('openhab');

I'm pretty sure I don't have the changes yet that injects that for me.

I get the following error when rules and items are included in that list.

2021-12-01 12:20:00.008 [WARN ] [.internal.OpenhabGraalJSScriptEngine] - Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabl
ed.
2021-12-01 12:20:00.085 [WARN ] [script.js.osgi                      ] - bundleContext is undefined             [osgi at source <unknown>, line 53]
2021-12-01 12:20:00.090 [WARN ] [script.js.osgi                      ] - Failed to get service org.openhab.core.items.ItemBuilderFactory: [object Error]                [osgi at source <unknown>, line 53]
2021-12-01 12:20:00.095 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: Failed to get any services of type(s): org.openhab.core.items.ItemBuilderFactory
        at <js>.getService(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/osgi.js:78) ~[?:?]
        at <js>.:anonymous(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/items/managed.js:11) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at <js>.:anonymous(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/items/items.js:8) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at <js>.:anonymous(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/rules/rules.js:10) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at <js>.:anonymous(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/rules/index.js:1) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:130) ~[bundleFile:?]
        at <js>.get rules(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/index.js:13) ~[?:?]
        at org.graalvm.polyglot.Context.eval(Context.java:379) ~[bundleFile:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[bundleFile:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[bundleFile:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[bundleFile:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[bundleFile:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1032) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotFunctionProxyHandler.invoke(PolyglotFunctionProxyHandler.java:154) ~[bundleFile:?]
        at com.sun.proxy.$Proxy525.apply(Unknown Source) ~[?:?]
        at org.openhab.core.model.script.actions.ScriptExecution.lambda$0(ScriptExecution.java:82) ~[bundleFile:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:184) ~[?:?]
        at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:87) ~[?:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]
2021-12-01 12:20:00.098 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'alarm_script' failed: org.graalvm.polyglot.PolyglotException: Error: Failed to get any services of type(s): org.openhab.core.items.ItemBuilderFactory

I get the following error when I include actions in that list:

2021-12-01 12:33:55.058 [WARN ] [.internal.OpenhabGraalJSScriptEngine] - Failed to retrieve script script dependency listener from engine bindings. Script dependency tracking will be disabled.
2021-12-01 12:33:55.084 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "getAllServiceReferences"
        at <js>.findServices(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/osgi.js:91) ~[?:?]
        at <js>.:anonymous(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/actions.js:25) ~[?:?]
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:130) ~[?:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:130) ~[?:?]
        at <js>.get actions(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/index.js:18) ~[?:?]
        at <js>.:program(<eval>:2) ~[?:?]
        at org.graalvm.polyglot.Context.eval(Context.java:379) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1035) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1051) ~[?:?]
        at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:327) ~[?:?]
        at jdk.internal.reflect.GeneratedMethodAccessor133.invoke(Unknown Source) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
        at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) ~[bundleFile:3.4.5]
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[bundleFile:3.4.5]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) ~[bundleFile:3.4.5]
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) ~[bundleFile:3.4.5]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[bundleFile:3.4.5]
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[bundleFile:3.4.5]
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:265) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:225) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:298) ~[bundleFile:3.4.5]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:217) ~[bundleFile:3.4.5]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[bundleFile:3.1.0]
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:273) ~[bundleFile:3.4.5]
        at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550) ~[bundleFile:9.4.43.v20210629]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1434) ~[bundleFile:9.4.43.v20210629]
        at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:294) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1349) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.43.v20210629]
        at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:82) ~[bundleFile:?]
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388) ~[bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:386) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [bundleFile:9.4.43.v20210629]
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [bundleFile:9.4.43.v20210629]
        at java.lang.Thread.run(Thread.java:829) [?:?]
2021-12-01 12:33:55.092 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'alarm_script' failed: org.graalvm.polyglot.PolyglotException: TypeError: undefined has no such function "getAllServiceReferences"

If I were to put a priority on these I'd put it on items since that will probably be the most used part of the library.

For rules and items it appears to be failing on line 11 in managed.js which is trying to get a reference to "org.openhab.core.items.ItemBuilderFactory" using OSGI. I don't see anything wrong with the code and can't imagine I have done something that might have broken this so am at a loss for how to proceed.

@rkoshak
Copy link
Contributor Author

rkoshak commented Dec 1, 2021

Since I'm not doing anything that involves the ItemBuilderFactory nor the ManagedItemProvider I commented that part of the code out and it seems to work well enough to get past this hurdle temporarily.

@digitaldan
Copy link
Contributor

I have seen this on a fresh OH install, but not my production one which is very strange. I'll take a look at it again.

@digitaldan
Copy link
Contributor

12:28:07.204 [DEBUG] [script.js.console                    ] - loading globals
12:28:07.564 [WARN ] [script.js.osgi                       ] - bundleContext is undefined		[osgi at source <unknown>, line 53]
12:28:07.575 [WARN ] [script.js.osgi                       ] - Failed to get service org.openhab.core.items.MetadataRegistry: [object Error]		[osgi at source <unknown>, line 53]
12:28:07.578 [WARN ] [script.js.osgi                       ] - bundleContext is undefined		[osgi at source <unknown>, line 53]
12:28:07.581 [WARN ] [script.js.osgi                       ] - Failed to get service org.eclipse.smarthome.core.items.MetadataRegistry: [object Error]		[osgi at source <unknown>, line 53]
12:28:07.607 [ERROR] [ab.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: Error: Failed to get any services of type(s): org.openhab.core.items.MetadataRegistry,org.eclipse.smarthome.core.items.MetadataRegistry
	at <js>.getService(webpack://@oh/./osgi.js?:78) ~[?:?]

This is also from a snapshot download, not sure what has changed.

@rkoshak
Copy link
Contributor Author

rkoshak commented Dec 1, 2021

Not to add to the woes but I'm also see the following when trying to access a Metadata value through the library.

2021-12-01 13:18:42.230 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (get) on org.openhab.core.items.MetadataRegistry failed due to: Unknown identifier: get
        at <js>.getValue(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/metadata/metadata.js:28) ~[?:?]
        at <js>.getMetadataValue(/openhab/conf/automation/lib/javascript/personal/node_modules/openhab/items/managed.js:124) ~[?:?]
        at <js>.:program(<eval>:9) ~[?:?]
        at org.graalvm.polyglot.Context.eval(Context.java:379) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.eval(DelegatingScriptEngineWithInvocable.java:51) ~[?:?]
        at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.eval(InvocationInterceptingScriptEngineWithInvocable.java:69) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) [?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1183) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:991) [bundleFile:?]
        at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:90) [bundleFile:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
        at java.lang.Thread.run(Thread.java:829) [?:?]
2021-12-01 13:18:42.235 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'all_away' failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (get) on org.openhab.core.items.MetadataRegistry failed due to: Unknown identifier: get

@digitaldan
Copy link
Contributor

well, i think i found probably what's causing this to fail in JS

On my production machine running 3.2.0-SNAPSHOT - Build #2581 the following code:

Object.keys(require('@runtime/osgi')).forEach(k => {
    console.log("@runtime Key:", k);
})

produces:

2021-12-01 13:21:15.487 [INFO ] [rg.openhab.automation.jsscripting.js] - @runtime Key: lifecycle
2021-12-01 13:21:15.487 [INFO ] [rg.openhab.automation.jsscripting.js] - @runtime Key: classutil
2021-12-01 13:21:15.488 [INFO ] [rg.openhab.automation.jsscripting.js] - @runtime Key: bundleContext

On a more recent milestone release, it outputs nothing. So something has changes with these globals.

@digitaldan
Copy link
Contributor

Ok, well looks like i had installed https://github.com/jpg0/ohj-support some time ago and forgot about it, so this was providing the missing bits. Let me see if we can do without is or if some of that needs to go into the JSScripting binding

@digitaldan
Copy link
Contributor

@jpg0 looks like i had your ohj-support library installed and forgot about it, it looks like this may be required. Do you see a way around this? or should we combine this code into the JSScripting binding ?

@digitaldan
Copy link
Contributor

digitaldan commented Dec 1, 2021

So i added in most of the classes untouched from https://github.com/jpg0/ohj-support into the binding and everything works again. @jpg0 these seem to be reasonable additions , so i don't have any problems adding them if you are ok? (i removed the sitemap support as well as the suspendible rule support as i did not see them used)

@jpg0
Copy link
Collaborator

jpg0 commented Dec 2, 2021

I have no problem with them being included.

Note that they are all fairly generic things though, so should probably be moved to the core scripting bundle rather than a language-specific one. I originally had them in the JS bundle for expediency, then moved them out to ohj-support so that the JS bundle remained as clean as possible for acceptance into openhab-addons.

@digitaldan
Copy link
Contributor

Sounds good, It looks like only the OSGiScriptExtensionProvider class and supporting classes for it are required? I think everything else is being provided by openHAB core? Does this sound right ?

@digitaldan
Copy link
Contributor

Providing this in core would also solve openhab/openhab-core#2173 as well, yes?

@rkoshak rkoshak mentioned this issue Dec 2, 2021
8 tasks
@rkoshak
Copy link
Contributor Author

rkoshak commented Dec 8, 2021

This appears to have been fixed in the latest version of the add-on (openhab/openhab-core#2433 (comment)). I'll close it but if I'm wrong and it covers other stuff not yet fixed please feel free to reopen it.

@rkoshak rkoshak closed this as completed Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants