Skip to content

Handle local Project binding write failures with typed results#78

Open
rtbenfield wants to merge 4 commits into
mainfrom
better-result-local-pin-write
Open

Handle local Project binding write failures with typed results#78
rtbenfield wants to merge 4 commits into
mainfrom
better-result-local-pin-write

Conversation

@rtbenfield

Copy link
Copy Markdown
Contributor

Implements phase two of the better-result error-handling plan by completing the local Project binding write path. Local pin writes and .gitignore updates now return typed better-result errors before controllers convert expected failures into CLI envelopes.

Changes

  • Local binding writes: packages/cli/src/lib/project/local-pin.ts now models serialization, filesystem, and cancellation outcomes for .prisma/local.json writes and .gitignore updates with local TaggedError variants.
  • Directory binding flow: bindProjectToDirectory composes the typed local-pin results and project/app controllers exhaustively convert binding failures into command-facing errors.
  • Error surface: docs/product/error-conventions.md defines LOCAL_STATE_WRITE_FAILED so local Project binding write failures have a stable structured code instead of leaking raw filesystem exceptions.
  • Coverage and plan tracking: Project/app binding tests cover blocked pin writes and blocked gitignore updates, phase one is marked complete, and phase two is marked complete with the known unrelated typecheck blocker.

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 test passed.
  • pnpm lint:skills passed.
  • pnpm build:cli passed.
  • pnpm --filter @prisma/cli exec tsc -p tsconfig.json is blocked by unrelated existing diagnostics in src/controllers/branch.ts, src/lib/app/branch-database.ts, tests/helpers.ts, tests/project-real-mode.test.ts, tests/publish-prep.test.ts, and tests/resolve-cli-version.test.ts.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7d214865-b396-41e5-bb05-273613b320f2

📥 Commits

Reviewing files that changed from the base of the PR and between 7f232f6 and 39c6029.

📒 Files selected for processing (1)
  • packages/cli/src/lib/project/setup.ts

Summary by CodeRabbit

  • Bug Fixes

    • Improved CLI error handling for failures saving local project state; surfaces a standardized error code and clearer operation/context details during project linking and deployment.
  • Documentation

    • Added a stable error code (LOCAL_STATE_WRITE_FAILED) and guidance for resolving local state write failures (e.g., permissions, filesystem issues).
  • Tests

    • Added tests covering local state write and .gitignore update failure scenarios across linking and deploy flows.

Walkthrough

This 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: handling local Project binding write failures by introducing typed results using the better-result pattern.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the implementation details, motivation, and verification status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch better-result-local-pin-write
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch better-result-local-pin-write

Comment @coderabbitai help to get the list of available commands and usage tips.

@rtbenfield rtbenfield marked this pull request as ready for review June 9, 2026 11:04

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Phase 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/cli exec tsc -p tsconfig.json to 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

📥 Commits

Reviewing files that changed from the base of the PR and between da7b057 and 7f232f6.

📒 Files selected for processing (9)
  • .agents/projects/better-result-error-handling.plan.md
  • docs/product/error-conventions.md
  • packages/cli/src/controllers/app.ts
  • packages/cli/src/controllers/project.ts
  • packages/cli/src/lib/project/local-pin.ts
  • packages/cli/src/lib/project/setup.ts
  • packages/cli/tests/app-controller.test.ts
  • packages/cli/tests/project-controller.test.ts
  • packages/cli/tests/project.test.ts

Comment thread packages/cli/src/lib/project/setup.ts Outdated
@rtbenfield rtbenfield changed the title Type local pin binding writes Handle local Project binding write failures with typed results Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant