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

[jsscripting] Globals cannot be injected automatically on Windows #11801

Closed
ghys opened this issue Dec 17, 2021 · 1 comment · Fixed by #11804 or #11805
Closed

[jsscripting] Globals cannot be injected automatically on Windows #11801

ghys opened this issue Dec 17, 2021 · 1 comment · Fixed by #11804 or #11805
Labels
bug An unexpected problem or unintended behavior of an add-on

Comments

@ghys
Copy link
Member

ghys commented Dec 17, 2021

The JSScripting add-on doesn't seem to load the global variables (the default behavior) for UI-created rules on Windows.
Note that this seems to happen even when the Use Built-in Global Variables option in Settings > Other Services > JS Scripting is set to Do Not Use Built-in Variables.

On the same snapshot on Linux, it seems to work.

Expected Behavior

The global variables should be loaded with no exception.

Current Behavior

This exception appears in the logs on the first execution of a script, regardless of the option above:

[ERROR] [g.internal.OpenhabGraalJSScriptEngine] - Could not inject global script
javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: '@jsscripting-globals'
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException(GraalJSScriptEngine.java:483) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:460) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:426) ~[?:?]
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) ~[java.scripting:?]
<snip>
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: Cannot load CommonJS module: '@jsscripting-globals'
        at com.oracle.truffle.polyglot.PolyglotMapAndFunction.apply(PolyglotMapAndFunction.java:46) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$3(OpenhabGraalJSScriptEngine.java:178) ~[?:?]
        at java.util.Optional.orElseGet(Optional.java:369) ~[?:?]
        at org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine.lambda$1(OpenhabGraalJSScriptEngine.java:178) ~[?:?]
        at <js>.:program(<eval>:1) ~[?:?]
        at org.graalvm.polyglot.Context.eval(Context.java:379) ~[?:?]
        at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458) ~[?:?]
        ... 71 more

Possible Solution

A workaround is to add explitely:

var runtime = require('@runtime');

to all scripts and use that, this works, but the exception is ugly and cannot be avoided.

Steps to Reproduce (for Bugs)

  1. Install the JSScripting add-on
  2. Create a ECMAScript 2021 script in the UI (Settings > Scripts) or a rule with a script action set to ECMAScript 2021.
  3. Run it

This might be because of path separators, for example here:

Context

The JSScripting add-on which is a big feature of openHAB 3.2 doesn't work well in the simplest scenario on Windows (e.g. for testing purposes).

Your Environment

On Windows, Zulu 11, fresh openHAB 3.2.0-SNAPSHOT - Build 2632,

@ghys ghys added the bug An unexpected problem or unintended behavior of an add-on label Dec 17, 2021
@digitaldan
Copy link
Contributor

oof, i'll get a fix in asap for that

digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Dec 17, 2021
kaikreuzer pushed a commit that referenced this issue Dec 17, 2021
digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Dec 17, 2021
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Dec 17, 2021
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
digitaldan added a commit to digitaldan/openhab-addons that referenced this issue Dec 17, 2021
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
kaikreuzer pushed a commit that referenced this issue Dec 17, 2021
Lets try this again, Fixes #11801

Signed-off-by: Dan Cunningham <[email protected]>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this issue Dec 30, 2021
Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this issue Dec 30, 2021
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
mischmidt83 pushed a commit to mischmidt83/openhab-addons that referenced this issue Jan 9, 2022
Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
Signed-off-by: Michael Schmidt <[email protected]>
mischmidt83 pushed a commit to mischmidt83/openhab-addons that referenced this issue Jan 9, 2022
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
Signed-off-by: Michael Schmidt <[email protected]>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this issue Jan 28, 2022
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this issue Jan 28, 2022
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this issue May 5, 2022
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
andan67 pushed a commit to andan67/openhab-addons that referenced this issue Nov 6, 2022
andan67 pushed a commit to andan67/openhab-addons that referenced this issue Nov 6, 2022
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
andrasU pushed a commit to andrasU/openhab-addons that referenced this issue Nov 12, 2022
andrasU pushed a commit to andrasU/openhab-addons that referenced this issue Nov 12, 2022
Lets try this again, Fixes openhab#11801

Signed-off-by: Dan Cunningham <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
2 participants