Repository navigation
fix(mocactl): a failed login names the control plane and the real error - #836
Conversation
A failed `mocactl login`, `mocactl sbx login` or TUI Login overlay printed a fixed sentence such as "the control plane is unavailable — try again shortly": not which control plane it tried, nor the HTTP status, the API's error code and message, or the network error that mocactl had already parsed into the ApiError. describeLoginError (core/messages.ts) keeps the friendly sentence, names the control plane at its configured URL (userinfo, query and fragment stripped), and adds the cause: "HTTP 503 redis_unavailable: <message>", or "HTTP 502, not an API answer: a proxy?" for a non-JSON body, or the network error with its cause code. All three login paths use it; sbx login keeps fail()'s exit codes (4 unreachable, 1 failed) and its own not-enrolled and token-code wording. networkError now folds in a cause's message when the cause has no code, so such a failure is no longer a bare "fetch failed". Closes rossoctl#700 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Summary
This PR makes all three login paths (mocactl login, mocactl sbx login, and the TUI Login overlay) say which control plane they tried and what came back: the HTTP status with the API's code and message, or the network cause. It also strips userinfo, query and fragment from the URL before printing it. Error-text sanitization (sanitizeRemote), exit codes and the not_enrolled and token-code wording are unchanged, and other describeError callers behave as before. One suggestion: sbx login still drops the URL for failures that are not ApiErrors. One nit about the error code being printed twice.
Author: webchang (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl src + tests), Security (secrets in output, sanitization)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: nothing failing; deploy-scripts, deploy-scripts-bash32 and k8s-kind-e2e still pending at submit time. This review was static (PR code was not run).
| if (end !== undefined) return end; | ||
| // A refusal `fail` words for itself (not enrolled, a token code) keeps its words; any other | ||
| // failure names the control plane tried and what came back (#700), at `fail`'s exit codes. | ||
| if (err instanceof ApiError && err.code !== 'not_enrolled' && !TOKEN_CODES.has(err.code)) { |
There was a problem hiding this comment.
suggestion — This branch only covers ApiErrors, so a non-ApiError failure still goes to failed(c, err) → fail()'s last branch and prints sbx: <message> with no control-plane URL. Example: /v1/discovery or /v1/auth/device answering 200 with a non-JSON body (a captive portal or proxy page) throws a SyntaxError from res.json(). The comment above says "any other failure names the control plane tried", and the PR body says the non-API case gets (from the control plane at …) on all three login paths. mocactl login and the overlay do that, but sbx login does not. Consider sending non-ApiErrors (other than the cancel/expiry ones deviceLoginEnd already handled) through describeLoginError(err, c.url) at SBX_EXIT.failed too, plus a test for it, or else narrow the comment and the PR description.
There was a problem hiding this comment.
Fixed in 53bc544. sbx login now sends every failure that fail does not word for itself through describeLoginError(err, c.url): anything but not_enrolled and the token codes, an ApiError or not. Exit codes are unchanged: 4 for unreachable, 1 otherwise. New test: /v1/discovery answers 200 with an HTML page, and the output is sbx: login failed: … (from the control plane at <URL>), exit 1. It fails without the change.
Assisted-By: Claude Code
| if (classify(err).kind === 'unavailable') | ||
| return sanitizeRemote(`${cp} is unavailable (${cause}) — try again shortly`); | ||
| // Most sentences name the control plane now; the server's own message ('show') does not. | ||
| return sanitizeRemote(text.includes(cp) ? `${text} (${cause})` : `${text} (${cp}: ${cause})`); |
There was a problem hiding this comment.
nit — When classify returns show and the body had no message, err.message falls back to the code (super(message ?? code)), so text is the bare code and the code appears twice: e.g. a 404 {"error":"not_found"} prints not_found (the control plane at https://…: HTTP 404 not_found), and a non-JSON 4xx prints http_404 (the control plane at https://…: HTTP 404, not an API answer: a proxy?). Maybe when err.message === err.code the sentence should start from the cause alone (e.g. the control plane at https://… refused the login (HTTP 404 not_found)).
There was a problem hiding this comment.
Fixed in 53bc544. When the body had no message (err.message === err.code), the sentence now starts from what happened: the control plane at <URL> refused the login (HTTP 404 not_found), and for a non-JSON 4xx … refused the login (HTTP 404, not an API answer: a proxy?). Both are new cases in messages.test.ts that fail without the change.
Assisted-By: Claude Code
…code twice A failure that is not an ApiError (a proxy's 200 page that is not JSON) now goes through describeLoginError on sbx login too, as on mocactl login and the overlay. And a body with no message of its own reads 'the control plane at URL refused the login (HTTP 404 not_found)', not the code twice (review suggestion and nit). Part of rossoctl#700 Assisted-By: Claude Code Signed-off-by: Rong Chang <[email protected]>
Takes upstream main at 1a7f41e (19 merges since 032c8f6): the sandbox idle lifetime across docs, control plane, clients and deploy (rossoctl#820, rossoctl#837, rossoctl#842, rossoctl#843), grant redemption (rossoctl#822), the lease-check log line (rossoctl#824), egress fixes (rossoctl#829, rossoctl#834), the mock wait (rossoctl#828), the deadline timer (rossoctl#835), the create rollback (rossoctl#832), multi refusals and the rossoctl#363 leftovers (rossoctl#833, rossoctl#838), the identity near-miss check (rossoctl#827), mocactl login errors (rossoctl#836), the ghostunnel probes (rossoctl#830), refusal-burst deferral (rossoctl#831), a sandbox-worker change (rossoctl#841) and the v0.11 doc truth (rossoctl#821). Conflicts (one): - deploy/sbx/README.md, the "Optional inputs" table. Upstream (rossoctl#843) rewrote the SBX_LIFETIME_DAYS row (the default idle lifetime, at most SBX_MAX_LIFETIME_DAYS) and added the SBX_MAX_LIFETIME_DAYS and SBX_LOWER_WORKSPACE_IDLE rows, which widened the table; the fork had added an SBX_GATE_RECORD_SCHEMA row at its end. Resolved by taking upstream's table whole and appending the fork's SBX_GATE_RECORD_SCHEMA row after SBX_PROFILE, then re-padding the table with prettier. The fork's env-file example line for SBX_GATE_RECORD_SCHEMA merged cleanly. Merged without markers, checked: setup.sh keeps the fork's SBX_GATE_RECORD_SCHEMA validation and its sbx-settings write (so it stays in the settings hash) beside upstream's SH_SANDBOX_MAX_LIFETIME_SECONDS; both ocp-sbx and ocp-combined patch-control-plane.yaml keep the optional SH_GATE_RECORD_SCHEMA from sbx-settings beside the new optional SH_SANDBOX_MAX_LIFETIME_SECONDS; setup.test.sh keeps the fork's cases beside upstream's. The fork's RUNBOOK, README and template-onboarding docs say nothing about sandbox lifetime, refusal bursts, login errors or the create rollback, so none needed a correction; GUIDE.md is unchanged and GUIDE.pdf is not regenerated. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Closes #700
What changed and why
mocactl login,mocactl sbx login, or the TUI Login overlay, which the onboarding overlay's login step reuses), the user saw one fixed sentence, for examplethe control plane is unavailable — try again shortly. It did not say which control plane was tried, and it left out the HTTP status, the API'serrorcode andmessage, and the network cause. mocactl had already parsed all of these into theApiError.describeLoginError(err, controlPlaneUrl)inpackages/mocactl/src/core/messages.ts. It keeps the existing friendly sentence, names the control plane by the URL it is configured with, and appends the real cause:the control plane at https://… is unavailable (HTTP 503 redis_unavailable: <message>) — try again shortly(HTTP 502, not an API answer: a proxy?)cannot reach the control plane at https://…: fetch failed (ECONNREFUSED). DNS (ENOTFOUND) and TLS cause codes appear the same way, and a dropped connection also shows its cause.(from the control plane at https://…)The URL loses any userinfo, query and fragment before it is printed, so a password typed into the URL never reaches the screen. All text still goes through
sanitizeRemote.headless.ts(cmdLogin, andcmdLoginTestUser's general case),sbx/commands.ts(cmdLogin), andviews/overlays/Login.tsx.sbx loginkeepsfail()'s exit codes (4 when unreachable, 1 otherwise) and its own wording fornot_enrolledand the token codes.sbx loginalso no longer prints the doubledcannot reach the sandbox control plane: cannot reach the control plane: ….networkError(api/errors.ts) now adds the cause's message when the cause has no.code, so such a failure is not justfetch failed.describeErrorcaller is unchanged: the URL is added only on login paths.Tests
Added tests, each run on main (with the
src/changes stashed) and then with the fix:test/headless.test.ts,cmdLogin: a 503 with{"error":"redis_unavailable","message":"redis is down"}fromPOST /v1/auth/device(parsed by the realerrorFromResponse), and a network error (ECONNREFUSEDcause, through the realnetworkError) on the device-token poll.login failed: the control plane is unavailable — try again shortlyandlogin failed: cannot reach the control plane: fetch failed (ECONNREFUSED)login failed: the control plane at http://cp is unavailable (HTTP 503 redis_unavailable: redis is down) — try again shortlyandlogin failed: cannot reach the control plane at http://cp: fetch failed (ECONNREFUSED)test/sbx-cli.test.ts, through the real HTTP client: a 503credential_unavailablewith a message fromPOST /v1/auth/device(exit 1), a non-JSON 502 (exit 1), and anENOTFOUNDonGET /v1/discovery(exit 4).sbx: the control plane is unavailable — try again shortlyandsbx: cannot reach the sandbox control plane: cannot reach the control plane: fetch failed (ENOTFOUND)test/overlay-login.test.tsx: a 500internal_errorin the overlay now showsthe control plane at http://cp is unavailable (HTTP 500 internal_error: boom). The existing retry test's expected text now includes the URL.test/messages.test.ts:describeLoginErrortable (a 5xx with and without a message, a non-JSON 5xx, a 4xxshow,identity_provider_misconfigured, a network error, a dropped connection, a non-API error). It also checks that the URL's password and query are never printed and that escape sequences are stripped.test/errors.test.ts:networkErrorfolds in a cause's message when the cause has no code.Before the fix: 18 of these tests fail (164 pass). After: all 182 pass. Full
@moca/mocactlsuite (vitest run --maxWorkers=2): 2019 passed and 4 skipped. Six timeouts on a heavily loaded machine (sbx-push,sbx-templates,sbx-up, none of them login code) passed when those files were rerun alone (133, 94 and 50 tests).tsc --noEmitis clean, and Prettier is clean.Out of scope
--recordfor login.mocactl sbxrefuses--record Fonlogin,logout,tokenandcredentialson purpose (NO_RECORDinsbx/cli.ts).mocactl loginhas no--recordat all: onlymocactl rundoes. Supporting login safely would need more than lifting the refusal. The device-token poll's request body carries the device code, and the recorder'sSECRET_FIELDSdoes not listdeviceCodetoday. The poll also writes one line every few seconds while it waits. That is a separate design decision, so this change leaves it out. The improved one-line error covers the "what came back" part of a login failure.--debug/MOCACTL_DEBUGswitch; a rotated failure log;mocactl doctor --report; a server-side maintenance code;X-Request-Id. Each is a larger feature, and some need server work.Every commit is signed off (DCO).
Assisted-By: Claude Code