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

ReferenceError: "me" is not defined in triggers.js #265

Open
Martin-Stangl opened this issue Oct 12, 2019 · 6 comments
Open

ReferenceError: "me" is not defined in triggers.js #265

Martin-Stangl opened this issue Oct 12, 2019 · 6 comments

Comments

@Martin-Stangl
Copy link

Full error message:
Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/javascript/personal/Papierschredder.js': ReferenceError: "me" is not defined in /etc/openhab2/automation/lib/javascript/core/triggers.js at line number 158

I did not define me in Papierschredder.js, as I don't use it anywhere. So far getTrName in triggers.js seems to be the only place demanding it.
Currently I found 2 workarounds:

  1. Globally define me, for e.g.: var me = __FILE__.split(__DIR__).pop();

  2. Provide a triggerName with each trigger.

My solution suggestions:

  1. Either just use the uuid if no triggerName was provided. If someone wants to be able to identify the source of their triggers, they have to do the works and provide triggerNames.

  2. Use the rule name instead of me. Probably needs to be done in JSRule then instead of getTrName: Go through all triggers in the JSRule function and if a trigger has no triggerName, generatge it there with uuid and name.

@Martin-Stangl
Copy link
Author

Not directly related to the issue, but two corrections to my workaround 1:

  1. __FILE__.split(__DIR__).pop() works on Linux, but not on Windows, as FILE always uses / as path separator, but DIR uses \ on Windows. Therefore __FILE__.split('/').pop() needs to be used.

  2. __FILE__.split('/').pop() works only for files loaded in with load(). The initial .js seems to be loaded using a reader. therefore FILE contains <eval> and not the file name. So it seems to be no clever way around to defining something like me = "myrule.js" for logging purposes. Still, the usage of me in getTrName is not clean and should be fixed.

Actually, I consider to give it a go myself to implement my solution suggestion 2, but I am a little unsure on how JSRuleNew fits into the picture. Is this just a work in progress of a new implementation of JSRule? Then I would need to implement my fix in both.

@5iver
Copy link
Member

5iver commented Oct 15, 2019

Thank you for reporting the problem and the analysis. The JS libraries will be completely reworked to match the Jython libraries once ES6 is available (OH JDK9 compatibility). If you want to clean them up, go ahead, otherwise I'll get in there at some point, but my time is very limited ATM.

@Martin-Stangl
Copy link
Author

Time is also an issue for me, but I feel motivated to find some currently and give it a try.

@5iver
Copy link
Member

5iver commented Oct 16, 2019

Just a heads up... you might want to look into #267. @jpg0 is proposing something that would likely cleanup this issue.

@Martin-Stangl
Copy link
Author

I am no JS expert, but if I understand it right, it would force us to fix this issue, as there would be no way to access me from within getTrName anymore.

@jpg0
Copy link

jpg0 commented Nov 27, 2019

FYI this did indeed force it to be fixed. (Well, you could probably explicitly assign the name to global.triggerName, but, let's not.) I just used the uuid if there was no name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants