http_client: dependency stub returns error object as first value instead of nil, err #12

Closed
opened 2026-09-20 19:30:15 +02:00 by michael · 0 comments
Owner

Problem

The dependency stub in http_client.lua returns the daw_error/v1
object as its first return value instead of nil, err:

local function module_stub(name, missing)
  return setmetatable({}, {
    __index = function()
      return function()
        return fail("submodule_unavailable", ...)   -- returns err only
      end
    end
  })
end

fail() in this file returns a single value (the error object). The
comment above the stub says it returns nil, daw_error/v1, and every
public function of the module is documented as result | nil, err.

Effect when socket.http, ltn12 or daw.common.json is missing:

local result, err = http.get(url, { timeout = 5 })
-- result is the error object, err is nil

A caller checking if not result treats the error as a successful
result. Reproduced by making require("socket.http") fail and calling
http.get.

Scope

  • Return nil, fail(...) from the stub (same as the public functions).
  • Add a test that simulates a missing dependency and checks
    result == nil, daw_error.is_error(err), err.data.dependency.
  • Check that the stub comment matches the behaviour afterwards.

Acceptance criteria

  • Stub returns nil, daw_error/v1
  • New test covers the missing-dependency path
  • fragjan code . and make test (5.1 and 5.4) pass

Found while working on DAW/daw-lua-net#10.

## Problem The dependency stub in `http_client.lua` returns the daw_error/v1 object as its first return value instead of `nil, err`: local function module_stub(name, missing) return setmetatable({}, { __index = function() return function() return fail("submodule_unavailable", ...) -- returns err only end end }) end `fail()` in this file returns a single value (the error object). The comment above the stub says it returns `nil, daw_error/v1`, and every public function of the module is documented as `result | nil, err`. Effect when socket.http, ltn12 or daw.common.json is missing: local result, err = http.get(url, { timeout = 5 }) -- result is the error object, err is nil A caller checking `if not result` treats the error as a successful result. Reproduced by making `require("socket.http")` fail and calling `http.get`. ## Scope - Return `nil, fail(...)` from the stub (same as the public functions). - Add a test that simulates a missing dependency and checks `result == nil`, `daw_error.is_error(err)`, `err.data.dependency`. - Check that the stub comment matches the behaviour afterwards. ## Acceptance criteria - [ ] Stub returns `nil, daw_error/v1` - [ ] New test covers the missing-dependency path - [ ] fragjan code . and make test (5.1 and 5.4) pass ## Related Found while working on DAW/daw-lua-net#10.
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#12
No description provided.