fix(opencode): return documented 404 on project update for missing project#1090
Conversation
…oject
PATCH /:projectID declares errors(400, 404) in its OpenAPI responses, but
Project.update threw a bare Error when the project row did not exist. A bare
Error is not a NamedError, so ErrorMiddleware fell through to its default branch
and returned an undocumented 500 instead of the declared 404.
- src/project/project.ts: throw the typed NotFoundError (already mapped to 404 by
ErrorMiddleware) instead of a bare Error on the missing-row path. NotFoundError
carries the same "Project not found: <id>" text in its data.message and is
exactly the 404 body shape (NotFoundError.Schema) the route already declares.
- test/project/project.test.ts: the existing not-found test asserted
.toThrow("Project not found: ..."), but NamedError sets Error.message to its
name ("NotFoundError"), so the business message now lives in data.message.
Updated the assertion to match {name, data.message}.
- test/server/project-routes.test.ts: new HTTP regression asserting PATCH on a
non-existent project returns 404 with the NotFoundError body.
No change to the success path, response body shape, status code of any
already-correct surface, or operationId. Mirrors #1067 / #1082 (aligning a route
to its already-declared 4xx contract).
ref #936
|
Warning Review limit reached
More reviews will be available in 14 minutes and 15 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request replaces a generic Error with a specific NotFoundError when a project is not found during an update. It also updates the corresponding unit tests and adds a new integration test file to verify that the PATCH route correctly returns a 404 status code and a NotFoundError response when a project does not exist. I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Summary
PATCH /:projectIDdeclareserrors(400, 404)in its OpenAPI responses, butProject.updatethrew a bareErrorwhen the project row did not exist. A bareErroris not aNamedError, soErrorMiddlewarefell through to its default branch and returned an undocumented 500 instead of the declared 404.Same contract-alignment pattern as #1067 / #1082: align a route to its already-declared 4xx instead of leaking a 500. No new contract surface — 404 was already declared.
Touched files
src/project/project.ts— throw the typedNotFoundError(mapped to 404 byErrorMiddleware) instead of a bareErroron the missing-row path. SameProject not found: <id>text now indata.message; body matches the declaredNotFoundError.Schema.test/project/project.test.ts— the existing not-found test asserted.toThrow("Project not found: ..."), butNamedErrorsetsError.messageto its name, so the business message moved todata.message. Updated to assert{ name, data.message }.test/server/project-routes.test.ts— new HTTP regression: PATCH on a non-existent project returns 404 with theNotFoundErrorbody.Verification
bun run typecheck(tsgo) — greentest/project/project.test.ts,test/server/project-routes.test.ts,test/server/route-inventory-harness.test.ts— 39 pass / 0 failRisk
Low. Pure error-contract alignment: success path, response body shape, status of already-correct surfaces, and operationId all unchanged. The only behavior change is the missing-project failure moving from an undocumented 500 to the already-declared 404.
Project.updatenow rejects withNotFoundErrorrather than a bareError; the one in-repo consumer asserting the old message was updated, and the front-end consumer (layout.tsxvia SDK) only observes the HTTP status, where 404 was already part of the declared contract.ref #936