Repository navigation
Description
Problem
1. A failed login doesn't say where it went or what came back
When the control plane answers with a 5xx, mocactl sbx login (and mocactl login, and the TUI) prints only:
sbx: the control plane is unavailable — try again shortly
classify() (packages/mocactl/src/api/errors.ts:136) maps every status ≥ 500, plus redis_unavailable, credential_unavailable and internal_error, to unavailable and keeps only the source. describeError() (packages/mocactl/src/core/messages.ts:46) then prints a fixed sentence. mocactl parses the status, the server's error code and message, and Retry-After into the ApiError, then drops them.
So the user can't tell:
-
Which control plane was tried. The URL comes from
--control-plane-url,MOCACTL_SBX_URL, the bound sandbox, or the one saved at an earlier login (sbxControlPlaneUrlinconfig.json). A user may not remember which one is in effect, and the message doesn't say. -
Why it failed. These all look alike:
- the control plane is down for maintenance
- a firewall or corporate proxy answered instead (a non-JSON page is reported as
http_<status>, or as "unavailable" when it is a 5xx) - the control plane has moved
- a real server bug
"Try again shortly" only helps in the maintenance case.
-
Which step failed:
GET /v1/discovery,POST /v1/auth/device, orPOST /v1/auth/device/token.
2. API failure details can't be seen or reported
mocactl has no --verbose or --debug flag and no env var for one. The only MOCACTL_* variables it reads are MOCACTL_SBX_URL and MOCACTL_VERSION. The only way to see a failing response today is to replay the requests with curl.
- Developers need these details for each request: method, URL, status, error code and message,
Retry-After, the network cause code (ECONNREFUSED,UND_ERR_HEADERS_TIMEOUT, …), and timing. - Users need a way to send those details to developers without leaking tokens. The control plane also returns no request ID, so there's nothing in a client-side report to match against the server logs.
Proposal
Error messages
- Name the control-plane URL and its source (flag, env, sandbox, saved config) in every login failure and every "unavailable" or "cannot reach" message.
- Put the HTTP status and the server's
errorcode, plusmessagewhen present, in the one-line error. For example:sbx: the control plane at https://… is unavailable (503 redis_unavailable) — try again shortly. - Give different advice for different causes:
- 503 with
Retry-Afteror a maintenance code: down for maintenance, retry in N seconds. - A non-JSON response: something other than the control plane answered (a proxy or firewall?).
- A DNS failure, a 404 at
/v1/discovery, or a redirect to another host: the control plane may have moved, so check the URL. - A 500: a server error to report (see below).
- 503 with
- Server side: add a maintenance signal the client can recognize, such as a 503 with
Retry-Afterand{"error":"maintenance"}. There is none today.
Logging and reporting
- An opt-in debug switch (
--debugand/orMOCACTL_DEBUG=1) that writes one line per request to stderr: method, URL, status, code, message, timing, and cause code. - A local, rotated log of failed requests under
$XDG_STATE_HOME/mocactl/, with the same fields. It should be 0600 like the sbx flight recorder (<state>/sbx/<id>.log). It must never record tokens,Authorizationheaders, device codes, or any body content other than the error JSON. - A command that builds a redacted report for a bug ticket, such as
mocactl doctor --report. It would include the mocactl version, Node version, platform, the effective control-plane URLs and their sources, and the recent failures from the log. - A request ID on every control-plane response (such as
X-Request-Id). The server logs it, and the client includes it in the error line and its log, so a user's report can be matched to the server's logs.
Acceptance criteria
- A login that fails with a 5xx prints the URL, its source, the step that failed, the status, and the server's error code.
- Maintenance, proxy/firewall, moved-control-plane, and server-error failures each get their own message.
- With the debug switch on, the outcome of every request appears on stderr. With it off, output is unchanged.
- A user can produce a redacted report file with one command and attach it to an issue.
Activity
mocactl: sbx login names the control plane for a non-API failure; no …
mocactl: a failed login names the control plane and what came back