Repository navigation
Description
Summary of the issue
When a request cannot reach the API, cf prints the same box whatever went wrong: an unresolvable host, an untrusted TLS certificate and a refused connection all show fetch failed, labelled Envelope Error, with no cause. A request that gets no response shows "timeout" after 60 seconds instead of saying which request timed out.
Two places drop the information:
src/api/client.tswraps the network failure in anApiErrorwith the undici error ascause, buthandleError()(src/lib/errors.ts) prints onlyerror.message(fetch failed) and labels any status-lessApiErrorEnvelope Error. The cause (getaddrinfo ENOTFOUND …,self-signed certificate,connect ECONNREFUSED …) is never shown.sendOnce()(src/api/fetch.ts) aborts a slow request withcontroller.abort("timeout").fetchthen rejects with the string"timeout", not anAbortError, so theApiTimeoutErrorbranch inclient.ts("Timeout exceeded when calling …") never matches and the string is printed as the message.
Expected behaviour
The error names the underlying cause, for example fetch failed: getaddrinfo ENOTFOUND api.example.invalid, and a timeout reports Timeout exceeded when calling GET /accounts/{account_id}/storage/kv/namespaces/{namespace_id}/keys., so a user can tell a DNS, certificate, proxy or network problem from an API problem.
Version of cf used
1.0.0-rc.6
System information and package versions
System:
OS: macOS 27.2.1
CPU: (8) arm64 Apple M3
Binaries:
Node: 26.13.1
npm: 11.20.0
npmPackages:
cf: 1.0.0-rc.6
Reproduction (optional)
CLOUDFLARE_API_BASE_URL points cf at an endpoint that fails in each way; any API command shows it.
export CLOUDFLARE_API_TOKEN=dummy CLOUDFLARE_ACCOUNT_ID=0123456789abcdef0123456789abcdef
# DNS failure, untrusted certificate, refused connection: all print the same box after ~1 s
CLOUDFLARE_API_BASE_URL=https://api.example.invalid/client/v4 npx [email protected] kv keys list --namespace-id ns1
CLOUDFLARE_API_BASE_URL=https://self-signed.badssl.com/client/v4 npx [email protected] kv keys list --namespace-id ns1
CLOUDFLARE_API_BASE_URL=http://127.0.0.1:59999/client/v4 npx [email protected] kv keys list --namespace-id ns1
# No response: a server that accepts the request and never answers
node -e 'require("http").createServer(() => {}).listen(8931)' &
CLOUDFLARE_API_BASE_URL=http://127.0.0.1:8931/client/v4 npx [email protected] kv keys list --namespace-id ns1Relevant error logs (optional)
The first three commands:
┌ APIError
│ fetch failed
│ Envelope Error
└
The last one, after 62 seconds:
┌ APIError
│ "timeout"
│ Envelope Error
└
Activity
test: show network failures and timeouts lose their cause (#795)
exKAZUu commentedon Nov 26, 2026
Since pull requests are limited to coordinated contributions during the release-candidate phase, I have not opened one here. A candidate fix with tests and a changeset is on a fork branch, in case it is useful: exKAZUu#1
It appends the
causechain to network failures on both the typed client andrequestApi()paths (including theAggregateErrorthatfetchgives for a host with IPv4 and IPv6 addresses), aborts timed-out requests without the"timeout"reason soApiTimeoutErroris reported, and keeps schema-backed help'sthe request timed outwording.pnpm checkpasses on it. Happy to open a PR here if you would like one.