fix(adapters/primitive): pcall return values unpacked incorrectly in run() #64

Closed
opened 2026-05-25 15:27:04 +02:00 by michael · 0 comments
Owner

Problem

adapters/primitive/init.lua M.run unpacks pcall incorrectly:

local ok, result, err = pcall(primitive.check, target, params)

pcall returns only two values: ok and the first return value of the
called function. err is always nil here. The fallback string always
fires when check() returns nil, masking the actual error from the primitive.

Fix

Use pcall for the error case only, call directly for the success path:

local ok, res_or_err = pcall(primitive.check, target, params)
if not ok then
  return nil, "[ERROR] primitive adapter: check() raised error: " .. tostring(res_or_err)
end
local result, err = res_or_err, nil  -- primitive returns result, nil | nil, err

Or unpack the two-value return properly after pcall succeeds.

Acceptance criteria

  • Primitive error message correctly propagated
  • pcall usage correct
## Problem `adapters/primitive/init.lua` M.run unpacks pcall incorrectly: ```lua local ok, result, err = pcall(primitive.check, target, params) ``` `pcall` returns only two values: `ok` and the first return value of the called function. `err` is always nil here. The fallback string always fires when check() returns nil, masking the actual error from the primitive. ## Fix Use pcall for the error case only, call directly for the success path: ```lua local ok, res_or_err = pcall(primitive.check, target, params) if not ok then return nil, "[ERROR] primitive adapter: check() raised error: " .. tostring(res_or_err) end local result, err = res_or_err, nil -- primitive returns result, nil | nil, err ``` Or unpack the two-value return properly after pcall succeeds. ## Acceptance criteria - [ ] Primitive error message correctly propagated - [ ] pcall usage correct
michael added this to the Basic Version milestone 2026-05-30 16:04:44 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/fragjan#64
No description provided.