[codex] Structure primary environment target failures #3413
main fromrefs/pull/3413/head·merged by juliusmarminge View on GitHubSummary#
- replace plain primary-target configuration and protocol errors with schema errors carrying target source and relevant structured fields
- wrap URL construction failures without copying raw URL values into outer error messages while retaining the exact parser cause
- make primary-target resolution accurately non-null and remove the unreachable generic HTTP-target error
This is stacked on #3409 because both changes share the primary-environment barrel and bootstrap tests.
Validation#
vp test apps/web/src/environments/primary/bootstrap.test.ts apps/web/src/authBootstrap.test.ts(23 tests)vp checkvp run typecheck
Note
Medium Risk Changes bootstrap/connection URL resolution and error surfaces at app startup; mis-handled throws could block connecting, though behavior is largely equivalent with clearer failures.
Overview
Primary environment target resolution now throws Effect Schema tagged errors instead of generic Error strings, with fields for target source (configured, window-origin, desktop-managed), URL kind, protocol, or which desktop bootstrap URLs are missing.
URL parsing goes through a shared parseTargetUrl helper that wraps URL failures in PrimaryEnvironmentUrlInvalidError, keeps the original parser cause, and avoids putting raw configured URLs in user-facing messages. Unsupported window protocols and partial desktop bootstrap data get PrimaryEnvironmentProtocolUnsupportedError and DesktopEnvironmentBootstrapIncompleteError respectively.
readPrimaryEnvironmentTarget is typed as always returning a target (desktop → configured → window origin), so resolvePrimaryEnvironmentHttpUrl drops the old null guard and the unreachable “unable to resolve HTTP base URL” error. The primary environment barrel re-exports the new error classes, type guards, and PrimaryEnvironmentTarget. Bootstrap tests cover invalid env URLs, missing wsBaseUrl, and file: origins.
Note
Replace generic errors with structured typed errors for primary environment target failures#
- Introduces
PrimaryEnvironmentRequestErrorin auth.ts, a Schema-backed tagged error carryingoperation,status,detail, optionalpairingLinkId/sessionId, andcause; replaces allBootstrapHttpErrorand genericErrorthrows across auth operations. - Adds three new error classes in target.ts:
PrimaryEnvironmentUrlInvalidError(sanitized message, no raw URL leakage),PrimaryEnvironmentProtocolUnsupportedError, andDesktopEnvironmentBootstrapIncompleteError. readPrimaryEnvironmentTargetnow returns a non-nullPrimaryEnvironmentTargetor throws a structured error; callers can no longer receivenull.- Adds
Schema.is-based type guards (isPrimaryEnvironmentRequestError,isPrimaryEnvironmentUrlInvalidError, etc.) and exports all new types from index.ts. - Behavioral Change: all callers that previously caught
BootstrapHttpErroror checked fornullfrom target resolution must now handle the new error types.
- 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
Approvability#
Verdict: Approved
This PR refactors error handling to use structured, typed error classes instead of generic Error objects. The changes are mechanical - replacing error constructors and adding type guards - with no changes to when errors are thrown or core runtime behavior.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this0e71885
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:
d57731c1-9877-498a-ab30-812d57cce5f4You 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.