Skip to content

[fork-ffi] exceptions: errorWithCause — In JS errorWithCause msg cause is new Error(msg, { cause }): the… #84

@Unisay

Description

@Unisay

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

In JS errorWithCause msg cause is new Error(msg, { cause }): the message remains exactly msg and the cause is stored separately, so message (errorWithCause msg cause) returns msg. The Lua version concatenates the cause into the message string ('msg\nCaused by: cause'). Because message is identity, message (errorWithCause "a" (error "b")) returns 'a\nCaused by: b' instead of 'a', diverging from the upstream contract that message returns the original message.

Current (Lua):

errorWithCause = (function(msg) return function(cause) return msg .. "\nCaused by: " .. cause end end)

Expected: message of an errorWithCause-built Error should equal the supplied msg (cause stored without altering the message).

Proposed fix:

With the flat-string Error model, faithfully preserving both message and a separate cause requires a richer representation (e.g. a table {message=..., cause=...}) and corresponding message/name/show readers. Minimally, keep the message pristine and store the cause out-of-band rather than concatenating into the message.

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