Skip to content

[fork-ffi] exceptions: catchException — In the error branch the handler result is returned without being… #81

@Unisay

Description

@Unisay

Package: purescript-lua-exceptions
File: src/Effect/Exception.lua
Function: catchException
Class: arity-drop Severity: high

In the error branch the handler result is returned without being executed. The handler c has PureScript type (Error -> Effect a); applying c(errorOrResult) yields an Effect a, which in this backend is a zero-arg thunk that must be invoked to actually run the effect and produce the value. The JS FFI calls it as c(e)() — note the trailing call. The Lua code stops at c(errorOrResult), so catchException returns the unexecuted thunk (a function) instead of the handled value, and the handler's side effects never run. Verified under Lua 5.1: with a handler that records a flag and returns a value, after catchException(c)(t)() the flag stayed false and the result was a function, not the value. This also breaks the library's own try (try = catchException (pure <<< Left) (Right <$> action)): on a thrown error try returns a function instead of Left error, so every downstream pattern-match on the Either fails.

Current (Lua):

else
          return c(errorOrResult)
        end

Expected: JS runs the handler effect: return c(e)(). catchException must return the value produced by running the handler's Effect, i.e. apply the returned thunk.

Proposed fix:

Change `return c(errorOrResult)` to `return c(errorOrResult)()`.

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