Transformation throws exception


(Yann) #1

Dear all,
I have a problem with 2.3.0
My openhab works very well and suddenly it’s bug.


2018-08-14 09:07:44.359 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]
org.openhab.core.transform.TransformationException: An error occurred while loading script.
at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [222:org.openhab.core.compat1x:2.2.0]

and few days later :

2018-09-17 15:17:33.923 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]

org.openhab.core.transform.TransformationException: An error occurred while loading script.

at org.openhab.core.transform.TransformationHelper$TransformationServiceDelegate.transform(TransformationHelper.java:67) [222:org.openhab.core.compat1x:2.2.0]

at org.openhab.binding.exec.internal.ExecBinding.transformResponse(ExecBinding.java:159) [225:org.openhab.binding.exec:1.11.0]

at org.openhab.binding.exec.internal.ExecBinding.execute(ExecBinding.java:128) [225:org.openhab.binding.exec:1.11.0]

at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [222:org.openhab.core.compat1x:2.2.0]

at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [222:org.openhab.core.compat1x:2.2.0]

Do you have any idea ?

Thanks a lot

edit :slight_smile:
my json

// Wrap everything in a function
(function(i) {
    //var array = i.split(i);
    //return array[0].length;
    if (input == 'video: muted\naudio: muted')
    	return "ON";
    else if (input == 'on')
    	return "ON";
    else
    	return "OFF";
})(input)
// input variable contains data passed by openhab
//JSON.parse(input).outputs[0].state;

(Yann) #2

I see one difference between my two openhab :

In *.items, with my first openhab i don’t have %s, in my second openhab with the bug I have %s.
Maybe sometimes parse json do a bug with %s of the item ?


(Rich Koshak) #3

Please use How to use code fences.

I know that JavaScript often has issues using == instead of ===. Try replacing the == with ===.


(Yann) #4

Thanks,
I try === now because my last try was a fail.

Yesterday new error :

2018-09-27 17:08:06.794 [WARN ] [lipse.jetty.server.AbstractConnector] - 
java.io.IOException: Too many open files
2018-09-27 17:08:08.429 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]
org.openhab.core.transform.TransformationException: An error occurred while loading script.

Strange : It’s always 10 days between the same bug


(Vincent Regaud) #5

The input variable is i not input

// Wrap everything in a function
(function(i) {
//var array = i.split(i);
//return array[0].length;
if (i == 'video: muted\naudio: muted')
    return "ON";
else if (i == 'on')
    return "ON";
else
    return "OFF";
})(input)
// input variable contains data passed by openhab
//JSON.parse(input).outputs[0].state;

(Yann) #6

=== and i :

// Wrap everything in a function
(function(i) {
    //var array = i.split(i);
    //return array[0].length;
    if (i === 'video: muted\naudio: muted')
    	return "ON";
    else if (i === 'on')
    	return "ON";
    else
    	return "OFF";
})(input)
// input variable contains data passed by openhab
//JSON.parse(input).outputs[0].state;

I try it, I will tell you in 10 days if I have the same problem. Very strange, each 10 days…


(Yann) #7

Dear all,
3 days later :

    2018-10-01 07:58:45.251 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]
    org.openhab.core.transform.TransformationException: An error occurred while loading script.

:frowning: I’m lost

I try to add try catch in my parse JSON : Do you think it’s right ?

// Wrap everything in a function
(function(i) {
    //var array = i.split(i);
    //return array[0].length;
    if (i === 'video: muted\naudio: muted')
    try {
        return "ON";
    } catch(e) {
        alert(e);
    }
    else if (i === 'on')
    try {
        return "ON";
    } catch(e) {
        alert(e); // error in the above string (in this case, yes)!
    }
    else
    try {
        return "OFF";
    } catch(e) {
        alert(e); // error in the above string (in this case, yes)!
    }
})(input)
// input variable contains data passed by openhab
//JSON.parse(input).outputs[0].state;

(Vincent Regaud) #8

Just keep the basics:

(function(i) {
    var response = '';
    if (i === 'video: muted\naudio: muted')
    	response = 'ON';
    else if (i === 'on')
    	response = 'ON';
    else
    	response = 'OFF';
    return response;
})(input)

(Yann) #9

Thanks, I try this code, more basic, I hope that it will work.
I let you know if it’s better or not.


(Yann) #10

Dear all,
Again, :frowning:

2018-10-06 02:37:03.040 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]
org.openhab.core.transform.TransformationException: An error occurred while loading script.

I try this :

(function(i) {
    if (i === 'video: muted\naudio: muted')
    	return "ON";
    else if (i === 'on')
        return "ON";
    else if (i === 'off')
        return "OFF";
})(input)

(Vincent Regaud) #11

There are no errors in that script that I can see.
Try:

(function(i) {
    if (i === 'video: muted\naudio: muted') {
    	return "ON";
    } else if (i === 'on') {
        return "ON";
    } else if (i === 'off') {
        return "OFF";
    }
})(input)

(Yann) #12

Same way, always the same error.
I have delete my item :

{exec="<[ON:/usr/local/bin/pjlink -p projector:4352 power:5000:JS(parseEpson.js)] >,,,,,,,,,,,}

(Vincent Regaud) #13

What version of OpenHAB are you running?
Try removing the javascript transform
Stop OH
Start OH
Install the transform again


(Yann) #14

I have this bug with OH Build 2.2 and 2.2.0 Javascript Transformation and after with
2.3 and 2.3.0 Javascript Transformation. I can try but i’m not sure that it corrects the problem.
Maybe I will try to downgrade java runtime.


(Vincent Regaud) #15

What version of Java are you running?
java -version


(Yann) #16

Actually 1.8.0_181
I’m not sure but I think when I did some tests before to choose OH I had _131 and no problem but maybe I didn’t do enough.


(Vincent Regaud) #17

It’s not java. Your version is correct


(Vincent Regaud) #18

Can you post you items and rules related to this error again, please?
I’d like to get to the bottom of it, because it should work.


(Yann) #19

items

// Projectors

Switch videoprojector1 "CCC-PROJ-01 ON/OFF"	(All, Projector) {exec="<[/usr/local/bin/pjlink -p CCC-PROJ-01:4352 power:5000:JS(parseEpson.js)] >[ON:/usr/local/bin/pjlink -p CCC-PROJ-01:4352 power on] >[OFF:/usr/local/bin/pjlink -p CCC-PROJ-01:4352 power off]"}
Switch videoprojector1mute   "CCC-PROJ-01 Mute"		(ProjectorMute)  {exec=">[ON:/usr/local/bin/pjlink -p CCC-PROJ-01:4352 mute all] >[OFF:/usr/local/bin/pjlink -p CCC-PROJ-01:4352 unmute all]"}
Switch videoprojector1pwr "CCC-PROJ-01 PWR"	(All, ProjectorPwr) {knx="2/0/1+<2/0/101"}

Switch videoprojector2 "CCC-PROJ-02 ON/OFF"	(All, Projector) {exec="<[/usr/local/bin/pjlink -p CCC-PROJ-02:4352 power:5000:JS(parseEpson.js)] >[ON:/usr/local/bin/pjlink -p CCC-PROJ-02:4352 power on] >[OFF:/usr/local/bin/pjlink -p CCC-PROJ-02:4352 power off]"}
Switch videoprojector2mute   "CCC-PROJ-02 Mute"		(ProjectorMute)  {exec=">[ON:/usr/local/bin/pjlink -p CCC-PROJ-02:4352 mute all] >[OFF:/usr/local/bin/pjlink -p CCC-PROJ-02:4352 unmute all]"}
Switch videoprojector2pwr "CCC-PROJ-02 PWR"	(All, ProjectorPwr) {knx="2/0/2+<2/0/102"}

parseEpson.js

(function(i) {
    if (i === 'on')
    	return "ON";
    else if (i === 'off')
        return "OFF";
})(input)

there is nothing in rules for this

all this “copy past” is the last version of my code, this code generate always the same error since the start
sometimes this error happen in 4 days, sometimes in 10 days.

2018-10-06 02:37:03.040 [ERROR] [ab.binding.exec.internal.ExecBinding] - transformation throws exception [transformation=JS(parseEpson.js), response=]
org.openhab.core.transform.TransformationException: An error occurred while loading script.

this morning I have deleted

<[/usr/local/bin/pjlink -p CCC-PROJ-01:4352 power:5000:JS(parseEpson.js)]

maybe I can try the binding Epson and stop to try this way to have ON OFF information

thanks for your help


(Vincent Regaud) #20

Since it happens intermittently, it could be that you have a time out and that would generate an error in the transformation.
Have you tried increasing the timeout to 10 seconds or maybe more?