Skip to content

Error formating exceptions from luerl_lib errors #87

@anjou-low

Description

@anjou-low

Hi!

Using version 0.3.0, it seems there is a problem with the formating of a Lua.RuntimeException with the following code:

code = """
  for i in pairs(nil) do
    print(i)
  end
"""

Lua.eval!(Lua.new(), code)
** (Lua.RuntimeException) Lua runtime error: cannot convert the given list to a string.

To be converted to a string, a list must either be empty or only
contain the following elements:

  * strings
  * integers representing Unicode code points
  * a list containing one of these three elements

Please check the given list or call inspect/1 to get the list representation, got:

[nil, nil]

    (elixir 1.18.4) lib/list.ex:1124: List.to_string/1
    (lua 0.3.0) lib/lua/util.ex:62: Lua.Util.format_error/1
    (lua 0.3.0) lib/lua/runtime_exception.ex:8: Lua.RuntimeException.exception/1
    (lua 0.3.0) lib/lua.ex:388: Lua.eval!/3
    iex:1: (file)

Note that the same issue arises when using ipairs instead of pairs

After a quick investigation it looks like the error returned by luerl is {:badarg, :next, [nil, nil]} is handled by the wrong branch here

{line, _type, message} ->

Fixing this does not solve the problem however as another error arises when trying to format the stacktrace

** (Lua.RuntimeException) Lua runtime error: protocol String.Chars not implemented for type Tuple.
Got value:

    {:luerl_lib_basic, :next, :undefined}

    (elixir 1.18.4) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.18.4) lib/string/chars.ex:22: String.Chars.to_string/1
    (elixir 1.18.4) lib/enum.ex:4497: Enum.map_intersperse_list/3
    (elixir 1.18.4) lib/enum.ex:1815: Enum.map_join/3
    (lua 0.3.0) lib/lua/util.ex:147: Lua.Util.format_function/2
    (lua 0.3.0) lib/lua/util.ex:104: anonymous fn/3 in Lua.Util.format_stacktrace/3
    (elixir 1.18.4) lib/enum.ex:1815: anonymous fn/2 in Enum.map_join/3
    (elixir 1.18.4) lib/enum.ex:4497: Enum.map_intersperse_list/3
    (elixir 1.18.4) lib/enum.ex:1815: Enum.map_join/3
    (lua 0.3.0) lib/lua/runtime_exception.ex:17: Lua.RuntimeException.exception/1
    (lua 0.3.0) lib/lua.ex:388: Lua.eval!/3
    iex:5: (file)

There seems to be a general issue with the handling of luerl's standard lib errors, e.g.

Lua.eval!(Lua.new(), "string.lower(nil)")
** (Lua.RuntimeException) Lua runtime error: protocol String.Chars not implemented for type Tuple.

Got value:

    {:luerl_lib_string, :lower, :undefined}

    (elixir 1.18.4) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.18.4) lib/string/chars.ex:22: String.Chars.to_string/1
    (elixir 1.18.4) lib/enum.ex:4497: Enum.map_intersperse_list/3
    (elixir 1.18.4) lib/enum.ex:1815: Enum.map_join/3
    (lua 0.3.0) lib/lua/util.ex:147: Lua.Util.format_function/2
    (lua 0.3.0) lib/lua/util.ex:104: anonymous fn/3 in Lua.Util.format_stacktrace/3
    (elixir 1.18.4) lib/enum.ex:1815: anonymous fn/2 in Enum.map_join/3
    (elixir 1.18.4) lib/enum.ex:4497: Enum.map_intersperse_list/3
    (elixir 1.18.4) lib/enum.ex:1815: Enum.map_join/3
    (lua 0.3.0) lib/lua/runtime_exception.ex:17: Lua.RuntimeException.exception/1
    (lua 0.3.0) lib/lua.ex:388: Lua.eval!/3
    iex:6: (file)

Do you want me to try something? If so do you have directions :P

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions