Audit run_rc()/run() callers for correct cause vs. raw-output distinction #56

Closed
opened 2026-08-16 08:58:54 +02:00 by michael · 1 comment
Owner

Problem

fs/dir.lua's remove_dir_recursive() currently (pre-#48-fix) passes
sys:run_rc()'s second return value as cause in both branches:

local rc, output = sys:run_rc("rm -rf -- " .. shell_quote(path))
if rc == nil then
  return err("rm_failed", "rm invocation failed", { cause = output, data = { path = path } })
end

sys.lua's run_rc() contract: on infrastructure failure it returns
nil, daw_error/v1 (output is a valid cause there); on a completed
process with non-zero exit, it returns rc, stdout (output is raw
process text, never a daw_error/v1, and must not be used as cause).

Found and fixed for fs/dir.lua's own two call sites during the
daw_i18n/v1 migration (DAW/daw-lua-common#48). This issue is to audit
whether other run_rc()/run() callers in the library make the same
mistake.

Scope

  • Audit all run_rc()/run() callers for the rc==nil vs rc!=0 (or
    equivalent) distinction
  • Confirm cause is only ever set to an actual daw_error/v1

DAW/daw-lua-common#48

## Problem `fs/dir.lua`'s `remove_dir_recursive()` currently (pre-#48-fix) passes `sys:run_rc()`'s second return value as `cause` in both branches: ```lua local rc, output = sys:run_rc("rm -rf -- " .. shell_quote(path)) if rc == nil then return err("rm_failed", "rm invocation failed", { cause = output, data = { path = path } }) end ``` `sys.lua`'s `run_rc()` contract: on infrastructure failure it returns `nil, daw_error/v1` (output is a valid cause there); on a completed process with non-zero exit, it returns `rc, stdout` (output is raw process text, never a daw_error/v1, and must not be used as `cause`). Found and fixed for fs/dir.lua's own two call sites during the daw_i18n/v1 migration (DAW/daw-lua-common#48). This issue is to audit whether other run_rc()/run() callers in the library make the same mistake. ## Scope - Audit all run_rc()/run() callers for the rc==nil vs rc!=0 (or equivalent) distinction - Confirm cause is only ever set to an actual daw_error/v1 ## Related DAW/daw-lua-common#48
Author
Owner

Audit result: no change needed

All callers of sys:run() / sys:run_rc() in production code were
checked for the cause/output mix-up this issue describes.

run_rc() callers -- rc == nil uses the daw_error/v1 as cause, rc ~= 0
puts the raw output into data.output:

  • fs/file.lua:187 (cp)
  • fs/dir.lua:187 (rm)

run() callers -- cause is always the second return value (a
daw_error/v1), never stdout text:

  • crypto/hash.lua:70 (sha_cmd, see DAW/daw-lua-common#54)
  • crypto/hash.lua:88 (run helper)
  • crypto/hmac.lua:115
  • fs/query.lua:102 (realpath)
  • fs/temp.lua:50 and :66 (mktemp)

No other caller uses command output as cause.

## Audit result: no change needed All callers of sys:run() / sys:run_rc() in production code were checked for the cause/output mix-up this issue describes. run_rc() callers -- rc == nil uses the daw_error/v1 as cause, rc ~= 0 puts the raw output into data.output: - fs/file.lua:187 (cp) - fs/dir.lua:187 (rm) run() callers -- cause is always the second return value (a daw_error/v1), never stdout text: - crypto/hash.lua:70 (sha_cmd, see DAW/daw-lua-common#54) - crypto/hash.lua:88 (run helper) - crypto/hmac.lua:115 - fs/query.lua:102 (realpath) - fs/temp.lua:50 and :66 (mktemp) No other caller uses command output as cause.
michael 2026-09-21 12:30:10 +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/daw-lua-common#56
No description provided.