terminal-code icon indicating copy to clipboard operation
terminal-code copied to clipboard

clean install fails to start - tode: fetch failed

Open anthony-somerset-cko opened this issue 2 months ago • 5 comments

on a Mac (arm64) (MacOS Golden Gate 27.0)

installed via the install script, running in ghostty, as soon as i attempt to load tode it gives an error

tode: fetch failed

i'd try to debug but there appear to be no debug options and i can't find any code string that matches in the repo

anthony-somerset-cko avatar Sep 18 '26 12:09 anthony-somerset-cko

with the help of claude we managed to debug this to an issue with the CA trust store in use due to our corporate MITM proxy - opening a PR for a generic fix

anthony-somerset-cko avatar Sep 18 '26 12:09 anthony-somerset-cko

summarised root cause output from my AI harness:

The error

tode: fetch failed — that's Node's generic message for any failed fetch, printed by main.ts's top-level catch, which only ever printed error.message. The real reason lives on error.cause, which was being thrown away, so the message was undiagnosable by design.

Reproduced it with tode --upgrade --check, then ran a bare fetch inside the exact runtime tode uses (the bundled Electron helper in ELECTRON_RUN_AS_NODE=1 mode) and printed the cause:

ERR TypeError fetch failed
CAUSE Error: self signed certificate in certificate chain
  code: 'SELF_SIGNED_CERT_IN_CHAIN'

Root cause

You're behind a TLS-inspecting proxy (standard corporate setup). Its root CA is installed in the macOS keychain, which is why curl to the same URLs returns 200. But Node verifies TLS against its own bundled Mozilla CA list and never consults the OS trust store, so every HTTPS request tode makes fails the handshake.

On a fresh install that bites at startup: tode boots → ensureServer() → ensureCodeServer() → downloads the code-server tarball from GitHub → handshake fails → fetch failed. Same for --upgrade and the terminal-browser release lookup.

anthony-somerset-cko avatar Sep 18 '26 12:09 anthony-somerset-cko

Thanks! Ill try to review and get this merged within a couple days

RobPruzan avatar Sep 24 '26 13:09 RobPruzan

@zenbu-bot

RobPruzan avatar Oct 30 '26 13:10 RobPruzan

tode prints only "tode: fetch failed" and drops the TLS cause when https fetches fail

Problem

Behind a TLS-inspecting proxy, every https fetch tode makes fails, and on a fresh install tode exits at startup with only tode: fetch failed. The CLI prints error.message and drops error.cause, so the real reason (for example SELF_SIGNED_CERT_IN_CHAIN) never appears. The reporter says the proxy's root CA is in the macOS keychain, but Node does not read that trust store.

Steps to reproduce

  1. Run npx tsc -p tsconfig.json > /dev/null; node scripts/write-cjs-boundary.js && node --test test/fetch-error.test.js.
  2. The test starts a local https server on 127.0.0.1 that uses a self-signed certificate.
  3. It creates a temporary install root that contains VERSION (0.0.1) and CHANNEL (stable).
  4. It runs node dist/main.js --upgrade --check with TODE_INSTALL_ROOT set to that root and TODE_RELEASE_ORIGIN set to the local server.
  5. It reads stderr.

Expected

stderr names the TLS failure, for example tode: fetch failed (self-signed certificate), so the user can see that the certificate is not trusted.

Actual

stderr is exactly tode: fetch failed, and the exit code is 1.

Cause

The top-level .catch in src/main.ts calls fail(error.message), which throws away error.cause, where undici stores the TLS error. The https fetches use the global fetch, which checks certificates against Node's bundled CA list: fetchVerified() in src/runtime/fetch.ts, plus latest(), release() and fetchBuild() in src/upgrade.ts. No code enables the OS trust store (for example --use-system-ca) or NODE_EXTRA_CA_CERTS. Not verified: that the macOS keychain CA is the only missing piece on the reporter's machine. The keychain step cannot be run on Linux.

Evidence

Reproduced on main@5b1a5e6 by the test test/fetch-error.test.js:

type: 'test'
  location: '/home/zenbu/base/test/fetch-error.test.js:11:1'
  failureType: 'testCodeFailure'
  error: 'stderr was: "tode: fetch failed\\n"'
  code: 'ERR_ASSERTION'
  name: 'AssertionError'
  expected:
  actual: |-
    tode: fetch failed
  operator: 'match'
  stack: |-
    TestContext.<anonymous> (/home/zenbu/base/test/fetch-error.test.js:49:10)
    process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    async Test.run (node:internal/test_runner/test:1054:7)
    async startSubtestAfterBootstrap (node:internal/test_runner/harness:296:3)
  ...
1..1
# tests 1
# suites 0
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 519.265855
Extra information
Job 41064601767-1
Handler issue.enhance
Classification bug
Sandbox docker · linux
Test command npx tsc -p tsconfig.json > /dev/null; node scripts/write-cjs-boundary.js && node --test test/fetch-error.test.js
Log GitHub Actions run

zenbu-bot[bot] avatar Oct 30 '26 13:10 zenbu-bot[bot]