Error helpers: fall back to sentinel when error.new() returns nothing #14

Closed
opened 2026-09-20 22:26:25 +02:00 by michael · 0 comments
Owner

Problem

The local error helper in daw-lua-net does not fully guarantee a
daw_error/v1-shaped return value:

local ok_new, obj, e = pcall(daw_error.new, _NAME, code, message, opts)
if not ok_new then
  return { ... sentinel ... }
end
return obj or e

If pcall succeeds but daw_error.new() returns neither obj nor
e, the helper returns nil, and the caller ends up with
return nil, nil -- silently violating the "always return a
daw_error/v1 on failure" rule the sentinel path exists to protect.

The same shape existed in 26 files of daw-lua-common and is fixed
there (DAW/daw-lua-common#53). It is not reachable with the current
daw.common.error.new(); this is defensive hardening against a broken
or replaced error facility.

Scope

  • Apply the same fix to the three helpers: fail_missing() in
    init.lua (returns nil, err), fail() in ip_utils.lua and
    fail() in http_client.lua.
  • Both a raising new() and one that returns nothing fall through to
    the same sentinel; data.detail names the no-result case.
  • Update the context of the three "new() crashed" resources in
    i18n/en.json (text unchanged) and recompute their source_hash
    in i18n/de.json.
  • One test that stubs daw.common.error with a new() returning
    nil, as in daw-lua-common.
  • Do not mix in other changes.

Acceptance criteria

  • All three helpers fall through to the sentinel
  • Resource contexts and hashes updated
  • New test is red before, green after the fix
  • fragjan code . and make test (5.1 and 5.4) pass

DAW/daw-lua-common#53

## Problem The local error helper in `daw-lua-net` does not fully guarantee a daw_error/v1-shaped return value: local ok_new, obj, e = pcall(daw_error.new, _NAME, code, message, opts) if not ok_new then return { ... sentinel ... } end return obj or e If `pcall` succeeds but `daw_error.new()` returns neither `obj` nor `e`, the helper returns `nil`, and the caller ends up with `return nil, nil` -- silently violating the "always return a daw_error/v1 on failure" rule the sentinel path exists to protect. The same shape existed in 26 files of daw-lua-common and is fixed there (DAW/daw-lua-common#53). It is not reachable with the current daw.common.error.new(); this is defensive hardening against a broken or replaced error facility. ## Scope - Apply the same fix to the three helpers: `fail_missing()` in `init.lua` (returns `nil, err`), `fail()` in `ip_utils.lua` and `fail()` in `http_client.lua`. - Both a raising `new()` and one that returns nothing fall through to the same sentinel; `data.detail` names the no-result case. - Update the context of the three "new() crashed" resources in `i18n/en.json` (text unchanged) and recompute their `source_hash` in `i18n/de.json`. - One test that stubs `daw.common.error` with a `new()` returning `nil`, as in daw-lua-common. - Do not mix in other changes. ## Acceptance criteria - [ ] All three helpers fall through to the sentinel - [ ] Resource contexts and hashes updated - [ ] New test is red before, green after the fix - [ ] fragjan code . and make test (5.1 and 5.4) pass ## Related DAW/daw-lua-common#53
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-net#14
No description provided.