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

TypeError: attribute name must be string, not 'int' #281

Open
justintimecode opened this issue Feb 27, 2025 · 0 comments
Open

TypeError: attribute name must be string, not 'int' #281

justintimecode opened this issue Feb 27, 2025 · 0 comments

Comments

@justintimecode
Copy link

justintimecode commented Feb 27, 2025

Hello,

I randomly have the following error, when a python code called from lua raise an exception.

TypeError: attribute name must be string, not 'int'

  File "lupa/lua54.pyx", line 1031, in lupa.lua54._LuaObject.__getitem__
  File "lupa/lua54.pyx", line 1049, in lupa.lua54._LuaObject._getitem
  File "lupa/lua54.pyx", line 1944, in lupa.lua54.execute_lua_call
  File "lupa/lua54.pyx", line 413, in lupa.lua54.LuaRuntime.reraise_on_exception
  File "lupa/lua54.pyx", line 2254, in lupa.lua54.py_object_getindex_with_gil
  File "lupa/lua54.pyx", line 2230, in lupa.lua54.getattr_for_lua
TypeError: attribute name must be string, not 'int'

I think the error comes from reraise_on_exception when indexing exception object, it tries to access to elements 0, 1 and 2.

    @cython.final
    cdef int reraise_on_exception(self) except -1:
        if self._raised_exception is not None:
            exception = self._raised_exception
            self._raised_exception = None
            raise exception[0], exception[1], exception[2]
        return 0

I am investigating a fix as follows

    @cython.final
    cdef int reraise_on_exception(self) except -1:
        if self._raised_exception is not None:
            exception = self._raised_exception
            self._raised_exception = None
-           raise exception[0], exception[1], exception[2]
+          raise exception
        return 0

and

    @cython.final
    cdef int store_raised_exception(self, lua_State* L, bytes lua_error_msg) except -1:
        try:
 -          self._raised_exception = tuple(exc_info())
 -          py_to_lua(self, L, self._raised_exception[1])
+          self._raised_exception =  exc_info()[1]
+          py_to_lua(self, L, self._raised_exception)
        except:
            lua.lua_pushlstring(L, lua_error_msg, len(lua_error_msg))
            raise
        return 0

and change the typing:

-     cdef tuple _raised_exception
+    cdef Exception _raised_exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant