Skip to content

[fork-ffi] exceptions: throwException — Error is represented as a plain Lua string (the message), and… #82

@Unisay

Description

@Unisay

Package: purescript-lua-exceptions
File: src/Effect/Exception.lua
Function: throwException
Class: semantics Severity: high

Error is represented as a plain Lua string (the message), and throwException raises it with error(err) at the default level (1). On Lua 5.1 (and all Lua versions), error() with a string argument at level >= 1 prepends source position info ('chunk:line: ') to the string. After catchException's pcall recovers it, the Error value is no longer the original message but 'file:line: '. Since message/name/showErrorImpl are all identity on the string, the recovered Error's message is corrupted. Verified under Lua 5.1: error('boom') round-tripped through pcall yields 'exc_test2.lua:1: boom' (not equal to 'boom'); with error('boom', 0) it yields exactly 'boom'. In PureScript/JS throwException throws the exact Error object and catchException catches it unchanged, so the message is preserved verbatim.

Current (Lua):

throwException = (function(err) return function() error(err) end end)

Expected: The thrown Error value (the message string) must survive the throw/catch round-trip unchanged, matching JS where throw e preserves e exactly.

Proposed fix:

Raise with level 0 to suppress position decoration: `function() error(err, 0) end`.

Found by the FFI audit; reproduced under Lua 5.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions