Skip to content

Network failures and timeouts print fetch failed / "timeout" with no cause #795

Backlog

Description

@exKAZUu

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.ts wraps the network failure in an ApiError with the undici error as cause, but handleError() (src/lib/errors.ts) prints only error.message (fetch failed) and labels any status-less ApiError Envelope Error. The cause (getaddrinfo ENOTFOUND …, self-signed certificate, connect ECONNREFUSED …) is never shown.
  • sendOnce() (src/api/fetch.ts) aborts a slow request with controller.abort("timeout"). fetch then rejects with the string "timeout", not an AbortError, so the ApiTimeoutError branch in client.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 ns1

Relevant error logs (optional)

The first three commands:

┌ APIError
│ fetch failed
│ Envelope Error
└

The last one, after 62 seconds:

┌ APIError
│ "timeout"
│ Envelope Error
└

Activity

  1. exKAZUu commented on Nov 26, 2026

    @exKAZUu
    Author

    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 cause chain to network failures on both the typed client and requestApi() paths (including the AggregateError that fetch gives for a host with IPv4 and IPv6 addresses), aborts timed-out requests without the "timeout" reason so ApiTimeoutError is reported, and keeps schema-backed help's the request timed out wording. pnpm check passes on it. Happy to open a PR here if you would like one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions