[codex] Structure client state key errors#3374
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Co-authored-by: codex <codex@users.noreply.github.com>
9a3c08a to
6274e96
Compare
ApprovabilityVerdict: Approved This PR replaces generic error throws with structured error classes for better debugging, adds Schema validation for key parsing, removes duplicate code, and includes comprehensive tests. The changes only affect error paths and don't alter happy-path runtime behavior. You can customize Macroscope's approvability policy. Learn more. |
Summary
Validation
pnpm vp test packages/client-runtime/src/state/assets.test.ts packages/client-runtime/src/state/entities.test.ts packages/client-runtime/src/state/threads-atoms.test.tspnpm vp check(20 pre-existing warnings)pnpm vp run typecheckNo active open PR modifies these files.
Note
Low Risk
Localized error-handling and key parsing in client state atoms; behavior on valid keys is unchanged and failures become more explicit rather than riskier.
Overview
Client-runtime atom family keys now fail with typed, inspectable errors instead of generic
Erroror uncheckedJSON.parsecasts.In
entities.ts,parseProjectKeyandparseThreadKeythrow distinct tagged errors that include the malformed key;parseProjectRefCollectionKeyvalidates JSON as an array of[string, string]tuples and wraps parse/decode failures with the original cause.assets.tsadds the same pattern for asset collection keys (EnvironmentId+AssetResource[]) viaparseAssetCollectionKeyandInvalidAssetCollectionKeyError.threads.tsdrops its duplicate thread-key helpers and uses sharedthreadKey/parseThreadKeyfromentities.ts. New unit tests cover malformed keys, invalid shapes, and preserved causes for assets and scoped entity keys.Reviewed by Cursor Bugbot for commit 6274e96. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Replace generic errors with structured tagged error classes for client state key parsing
InvalidAssetCollectionKeyError,InvalidScopedProjectKeyError,InvalidScopedThreadKeyError, andInvalidScopedProjectRefCollectionKeyErrorasSchema.TaggedErrorClassinstances, each carrying the offending key and underlying cause.parseAssetCollectionKey,parseProjectKey,parseThreadKey, andparseProjectRefCollectionKeyutilities that validate key shape viaeffect/Schemaand throw the appropriate structured error on failure.createAssetEnvironmentAtomsandcreateEnvironmentThreadStateAtomsto use these shared parse utilities instead of inlineJSON.parsecalls.Erroron malformed keys will now receive typed tagged errors with structured fields.Macroscope summarized 6274e96.