fix(web): return graceful error for unknown search context - #1362
Conversation
context:<value> resolves a named search context. When the context did not exist, onExpandSearchContext threw a plain Error, which is not caught by the SyntaxError-only handler and crashed the request. Throw a ServiceErrorException with SEARCH_CONTEXT_NOT_FOUND so it returns a clean 404 instead. Fixes sourcebot-dev#1312
Walkthrough
ChangesSearch Context Error Handling
Estimated code review effort: 2 (Simple) | ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Fixes #1312
Problem
Searching with
context:<value>(e.g.Helpers context:0) crashes the request when no search context with that name exists.context:resolves a named search context. Inpackages/web/src/features/search/parser.ts,onExpandSearchContextlooks the name up and, when it's missing, throws a plainError. The surroundingcatchonly mapsSyntaxErrorto aServiceErrorException; every other error is re-thrown as-is, so this one escapes the search action and surfaces as a server crash instead of a clean error.Fix
Throw a
ServiceErrorExceptionwith the existingSEARCH_CONTEXT_NOT_FOUNDerror code (HTTP 404) instead of a plainError.sew()already serializesServiceErrorExceptioninto a proper service-error response, so the user now gets a clear "Search context not found" message rather than a crashed request. All imports needed were already present.Tests
Added
parser.test.ts:ServiceErrorExceptioncarryingSEARCH_CONTEXT_NOT_FOUND(previously a plain Error / crash);Both pass.
tsc --noEmitis clean for the web package.Summary by CodeRabbit
Bug Fixes
contextvalue that references a non-existent search context no longer crashes. It now returns a graceful “not found” error response with appropriate error details.Tests
Note
Low Risk
Localized change to search query parsing error handling with tests; no auth, data, or broad API behavior changes.
Overview
When a search query uses
context:with a name that does not exist, the parser now raisesServiceErrorExceptionwithSEARCH_CONTEXT_NOT_FOUND(404) instead of a plainError, so the search path returns a structured “not found” response instead of crashing.parser.test.tsadds coverage for the missing-context error and for successful context expansion into repo names.Reviewed by Cursor Bugbot for commit ed5fb68. Bugbot is set up for automated code reviews on this repo. Configure here.