Handle local Project binding write failures with typed results#78
Handle local Project binding write failures with typed results#78rtbenfield wants to merge 4 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughThis PR implements structured error handling for local project binding operations in the CLI. It adds the LOCAL_STATE_WRITE_FAILED product error code in docs, defines exported TaggedError variants and a ProjectDirectoryBindingError union, refactors writeLocalResolutionPin and ensureLocalResolutionPinGitignore to return Result types, updates bindProjectToDirectory to return Result and adds projectDirectoryBindingErrorToCliError, updates controllers to convert and throw CLI errors on binding failures, and adds tests covering pin/gitignore failure scenarios. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.agents/projects/better-result-error-handling.plan.md (1)
46-68:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winPhase 2 status conflicts with its own acceptance criteria.
Line 46 says Phase 2 is complete with typecheck blocked, but Line 67 still requires
pnpm --filter@prisma/cliexec tsc -p tsconfig.jsonto pass. Please update one side so completion criteria are internally consistent.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In @.agents/projects/better-result-error-handling.plan.md around lines 46 - 68, The plan's Phase 2 completion flag conflicts with its Acceptance Criteria: either mark Phase 2 as still in-progress (remove the "Complete" check) or relax the Acceptance Criteria to no longer require the full TypeScript check; update the Phase 2 status line and/or the Acceptance Criteria so they are consistent, ensuring the text around "Phase 2" and the acceptance item that references "pnpm --filter `@prisma/cli` exec tsc -p tsconfig.json" are reconciled and reflect the intended gating condition.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cli/src/lib/project/setup.ts`:
- Around line 79-85: The LocalResolutionPinSerializationError is an invariant
(serialization) bug and should not be converted into a user-recoverable
LOCAL_STATE_WRITE_FAILED; update the matchError branch handling
LocalResolutionPinSerializationError (the mapping in
bindProjectToDirectory/serializeLocalResolutionPin error handling) to propagate
or reclassify it as an internal/unexpected error instead of calling
localStateWriteFailedError — preserve any useful metadata like pinPath but
return/throw an internal error (or rethrow the original
LocalResolutionPinSerializationError) so callers do not treat it as a
filesystem-permissions retryable failure.
---
Outside diff comments:
In @.agents/projects/better-result-error-handling.plan.md:
- Around line 46-68: The plan's Phase 2 completion flag conflicts with its
Acceptance Criteria: either mark Phase 2 as still in-progress (remove the
"Complete" check) or relax the Acceptance Criteria to no longer require the full
TypeScript check; update the Phase 2 status line and/or the Acceptance Criteria
so they are consistent, ensuring the text around "Phase 2" and the acceptance
item that references "pnpm --filter `@prisma/cli` exec tsc -p tsconfig.json" are
reconciled and reflect the intended gating condition.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 197ade44-350e-4bb8-ac3a-fe8d49f03ded
📒 Files selected for processing (9)
.agents/projects/better-result-error-handling.plan.mddocs/product/error-conventions.mdpackages/cli/src/controllers/app.tspackages/cli/src/controllers/project.tspackages/cli/src/lib/project/local-pin.tspackages/cli/src/lib/project/setup.tspackages/cli/tests/app-controller.test.tspackages/cli/tests/project-controller.test.tspackages/cli/tests/project.test.ts
Implements phase two of the better-result error-handling plan by completing the local Project binding write path. Local pin writes and
.gitignoreupdates now return typedbetter-resulterrors before controllers convert expected failures into CLI envelopes.Changes
packages/cli/src/lib/project/local-pin.tsnow models serialization, filesystem, and cancellation outcomes for.prisma/local.jsonwrites and.gitignoreupdates with localTaggedErrorvariants.bindProjectToDirectorycomposes the typed local-pin results and project/app controllers exhaustively convert binding failures into command-facing errors.docs/product/error-conventions.mddefinesLOCAL_STATE_WRITE_FAILEDso local Project binding write failures have a stable structured code instead of leaking raw filesystem exceptions.Why
This keeps expected local state failures typed at the owned filesystem boundary while preserving existing successful output such as
Saved .prisma/local.json. A dedicated error code is necessary because write failures are not stale local state; callers need a distinct recovery path for filesystem or permission problems.Verification
pnpm testpassed.pnpm lint:skillspassed.pnpm build:clipassed.pnpm --filter @prisma/cli exec tsc -p tsconfig.jsonis blocked by unrelated existing diagnostics insrc/controllers/branch.ts,src/lib/app/branch-database.ts,tests/helpers.ts,tests/project-real-mode.test.ts,tests/publish-prep.test.ts, andtests/resolve-cli-version.test.ts.