Giter Club home page Giter Club logo

Comments (3)

kmike avatar kmike commented on July 26, 2024

Is it a bug or an intended behaviour?

from lupa.

scoder avatar scoder commented on July 26, 2024

At least, it doesn't crash. These things used to. :)

Note that the pcall(lua_func) essentially just unpacks both Lua functions and calls one with the other as argument inside of Lua, so the Lua error doesn't actually pass through Python at all here.

The other way is tricky because supporting pcall(), correct me if I'm wrong, would mean that we translate a Python exception into a Lua longjmp() error to pass it on to Lua, and then detect and translate it back into a Python exception when it turns out that Lua didn't handle it and passed it back to Lupa (i.e. when there is no pcall() wrapping it).

I wouldn't call it "intended behaviour", but I'm not sure it's worth changing.

from lupa.

kmike avatar kmike commented on July 26, 2024

I see, thanks for explanation.

I worked around it by wrapping Python functions to a decorator that converts Python exceptions to False, repr(exception) and return values to True, result; in Lua these Python functions are wrapped in a Lua decorator which raises an error if status is False (these errors can be catched by pcall) and returns the result otherwise.

This means that Python exceptions are not propagated back to Python as-is when they are not handled, they are converted to LuaErrors. For my use cases it is even better because for these new errors error messages include line numbers. Maybe in future I'll attach original Python exception objects to errors as userdata; for the current use cases repr is enough.

It seems both behaviours have their use cases: raising original errors and raising wrapped errors, even in a single runtime.

At the moment I don't have plans to work on it further because an existing solution works well enough, but supporting something like this directly in lupa could help to clean up some of the messy code. Creating an existing workaround was quite tricky, and it has edge cases with coroutines (Python decorator doesn't fix values sent using coroutine.send).

from lupa.

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.