Giter Site home page Giter Site logo

Comments (9)

mjcumming avatar mjcumming commented on June 29, 2024

Hang on, still working on understanding the problem....

from openhab-helper-libraries.

5iver avatar 5iver commented on June 29, 2024

I have an update for the logging, which may fix this, and also adds a log attribute to the function as is done to a rule class. It's currently in the lucid migration branch, and I hope to have this merged by the end of the year, assuming there's someone to test it!

If you wanted to look at it, grab the core.rules.py from that branch. But now that I think of it, you may need the core.log.py and configuration.py too...

from openhab-helper-libraries.

mjcumming avatar mjcumming commented on June 29, 2024

The files from the lucid branch look the same as in the main branch - last commit was 15 days ago.

from openhab-helper-libraries.

diijkstra avatar diijkstra commented on June 29, 2024

I think this is a limitation of ESH, exception which is not handled by jython is logged with simple one liner. Are you sure, that line number is from offending module? For me, line is always set to line number of script (rule .py file) which is being run.

To debug, you can try to add try/except block which logs exception with full stack:

try:
    import foo
except Exception as ex:
    log.error(traceback.format_exc()) # assuming log is logger
    raise ex # optional, makes ESH think that exception was thrown here

So this error:

18:54:39.189 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/200_rules/foo.py': NameError: name 'foo' is not defined in <script> at line number 17

is now:

18:55:27.092 [ERROR] [ipse.smarthome.automation.rules] - Traceback (most recent call last):
  File "<script>", line 17, in <module>
  File "/openhab/conf/automation/lib/python/foo.py", line 1, in <module>
    bar
NameError: name 'bar' is not defined

18:55:27.094 [ERROR] [ript.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/200_rules/foo.py': NameError: name 'foo' is not defined in <script> at line number 20

Same thing happens when code is executed.

from openhab-helper-libraries.

mjcumming avatar mjcumming commented on June 29, 2024

Yes, the line number for the error comes from the script loading the module. Thank you for the work around, hope there is long term more elegant solution

from openhab-helper-libraries.

diijkstra avatar diijkstra commented on June 29, 2024

I think you can safely put most stuff inside try block, imports, rules, initialization etc. Only thing you need to have outside is logger. @rule decorator adds these try/except to your rules by default.

I think that proper solution can be implemented only on ESH side. If I remember correctly, .py rule file is read and run via jython interpreter as script (not read by jython from file, hence <script> instead file path in jython stack trace. Since nothing is handling an error, ESH is just logging where it went bad.

from openhab-helper-libraries.

5iver avatar 5iver commented on June 29, 2024

The files from the lucid branch look the same as in the main branch - last commit was 15 days ago.

I forgot... I haven't synced yet. Hoping to get this done in the next few hours. IMO, @diijkstra 's issue is the proper solution though. Until then, core.log.log_traceback can be used to decorate classes, methods and functions in modules. I think this is what you are looking for. The change I mentioned decorates the rule callback (Action).

from openhab-helper-libraries.

5iver avatar 5iver commented on June 29, 2024

There are a couple challenges to work out with migrating lucid, so I've added the changes I was referring to into master.

from openhab-helper-libraries.

5iver avatar 5iver commented on June 29, 2024

@diijkstra, do you planning to submit a PR to openhab-core?

from openhab-helper-libraries.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.