Skip to content

bb CLI: "Error: fetch failed" discards the error cause, making an unreachable backend indistinguishable from a dead one #1189

Closed

Description

@sholub-dev

Version: bb 0.36.0 (macOS)

Problem

Any backend-touching command fails with no diagnostic information:

$ bb thread list --json
Error: fetch failed

fetch failed is a Node constant used for every fetch failure. The real error is on error.cause and is discarded, so "blocked by a sandbox/firewall" is indistinguishable from "bb is not running".

Steps to reproduce

Point the CLI at an address nothing is serving:

$ BB_SERVER_URL=http://127.0.0.1:1 bb thread list --json
Error: fetch failed

The same output appears for any connect-level failure — refused, blocked, wrong port, wrong host — because the message is a constant. bb status still succeeds throughout, since it reads local files and never contacts the backend, which makes it look like a partial outage.

Root cause

The cause carries the diagnosis. Blocked by a sandbox:

cause = connect EPERM 127.0.0.1:38886
        code=EPERM  errno=-1  syscall=connect  port=38886

EPERM means the server is healthy and the caller isn't permitted to reach it; ECONNREFUSED would mean it's down. That distinction is present in the error object and never surfaces.

Where it is dropped

console.error(`Error: ${ii(r)}`), process.exit(1)

function ii(e){ return e instanceof Error ? e.message : String(e) }

ii reads .message only. grep -c "\.cause" over host-daemon/dist/bb returns 0. The exit code is 1 for all failures, so there is nothing to branch on either.

Fix

function ii(e){
  if (!(e instanceof Error)) return String(e);
  let msg = e.message, c = e.cause;
  while (c instanceof Error) { msg += ': ' + c.message; c = c.cause; }
  return msg;
}

Verified against the live failure:

current   -> Error: fetch failed
unwrapped -> Error: fetch failed: connect EPERM 127.0.0.1:38886 - Local (0.0.0.0:0)

Also worth considering: a distinct exit code for connection failures, and mapping ECONNREFUSED to bb is not running at <serverUrl> and EPERM/EACCES to cannot reach bb at <serverUrl> - connection blocked.

Activity

  1. added theissue type on Aug 8, 2026
  2. self-assigned this
    on Aug 10, 2026
  3. added a commit that references this issue on Aug 10, 2026
    34c8fa0
  4. added a commit that references this issue on Aug 14, 2026
    e24bbb0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions