[codex] Structure primary environment request failures #3409
main fromrefs/pull/3409/head·merged by juliusmarminge View on GitHubSummary#
- replace unstructured primary-environment HTTP failures with one schema error carrying operation, status, relevant resource identifiers, and the exact cause
- keep user-facing messages derived from safe structured HTTP error fields or code-owned fallbacks
- centralize the meaningful HTTP-to-request-error mapping on the error class and export its schema predicate
Validation#
vp test apps/web/src/authBootstrap.test.ts apps/web/src/environments/primary/bootstrap.test.tsvp checkvp run typecheck
Note
Medium Risk Touches auth bootstrap, session/pairing APIs, and error types callers may catch; behavior should stay similar but failure objects and predicates changed.
Overview
Replaces ad-hoc BootstrapHttpError and generic Error throws with a single PrimaryEnvironmentRequestError (Effect Schema tagged error) for primary-environment HTTP calls.
Each failure now carries operation (e.g. exchange-bootstrap-credential, list-pairing-links), status, user-facing detail, optional pairingLinkId / sessionId, and the original cause. Mapping is centralized in PrimaryEnvironmentRequestError.fromCause, which derives status and messages from structured HTTP errors or code-owned fallbacks; bootstrap credential exchange still applies friendly pairing-token copy via formatDetail.
isTransientBootstrapError now treats transient retries using the new error’s status. context.ts descriptor fetch uses the same error type. Public exports add PrimaryEnvironmentRequestError and isPrimaryEnvironmentRequestError.
The invalid-pairing-token test now asserts the structured error shape (including preserved EnvironmentAuthInvalidError cause) instead of only matching a thrown message string.
Note
Replace ad-hoc errors with structured PrimaryEnvironmentRequestError in primary environment auth#
- Introduces
PrimaryEnvironmentRequestError, a tagged error class withoperation,status,detail, optionalpairingLinkId/sessionId, andcausefields, replacing genericErrorandBootstrapHttpErroracross all primary environment request functions inauth.tsandcontext.ts. - Exports
isPrimaryEnvironmentRequestErrortype guard from the primary environment module so callers can discriminate errors by operation and status. - Updates
isTransientBootstrapErrorto useisPrimaryEnvironmentRequestErrorinstead of the now-removedisBootstrapHttpError. - Behavioral Change: All primary environment request failures now reject with
PrimaryEnvironmentRequestErrorinstead ofBootstrapHttpErroror genericError; callers that catch and inspect error types will need to update their checks.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved
This PR refactors error handling by replacing generic errors with a structured
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).PrimaryEnvironmentRequestErrorclass. The change is mechanical - errors are thrown at the same points with equivalent messages, just with better structure for downstream handling.juliusmarminge merged thisc3e3e26
juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
13e08d2a-2d0c-4909-a89e-fd0e6c334b80You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.