Skip to content

fix(web): return graceful error for unknown search context - #1362

Merged
brendan-kellam merged 5 commits into
sourcebot-dev:mainfrom
rachit367:rachit367/fix-search-context-crash
Aug 4, 2026
Merged

fix(web): return graceful error for unknown search context#1362
brendan-kellam merged 5 commits into
sourcebot-dev:mainfrom
rachit367:rachit367/fix-search-context-crash

Conversation

@rachit367

@rachit367 rachit367 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

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. In packages/web/src/features/search/parser.ts, onExpandSearchContext looks the name up and, when it's missing, throws a plain Error. The surrounding catch only maps SyntaxError to a ServiceErrorException; 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 ServiceErrorException with the existing SEARCH_CONTEXT_NOT_FOUND error code (HTTP 404) instead of a plain Error. sew() already serializes ServiceErrorException into 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:

  • unknown context → rejects with a ServiceErrorException carrying SEARCH_CONTEXT_NOT_FOUND (previously a plain Error / crash);
  • existing context → expands into its repo set.

Both pass. tsc --noEmit is clean for the web package.

Summary by CodeRabbit

  • Bug Fixes

    • Searching with a context value that references a non-existent search context no longer crashes. It now returns a graceful “not found” error response with appropriate error details.
  • Tests

    • Added coverage verifying correct errors for missing search contexts and proper expansion of valid contexts into associated repositories.

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 raises ServiceErrorException with SEARCH_CONTEXT_NOT_FOUND (404) instead of a plain Error, so the search path returns a structured “not found” response instead of crashing.

parser.test.ts adds 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.

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
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

onExpandSearchContext now throws a structured ServiceErrorException for missing search contexts instead of a generic error. Tests cover missing-context handling and repository expansion. CHANGELOG.md records the fix.

Changes

Search Context Error Handling

Layer / File(s) Summary
Structured missing-context error
packages/web/src/features/search/parser.ts
onExpandSearchContext throws ServiceErrorException with HTTP 404, SEARCH_CONTEXT_NOT_FOUND, and the missing context name.
Parser tests and changelog
packages/web/src/features/search/parser.test.ts, CHANGELOG.md
Tests cover the rejected missing-context lookup and successful repository expansion. The changelog documents the fixed crash path.

Estimated code review effort: 2 (Simple) | ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the fix for unknown search context errors.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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.

@brendan-kellam
brendan-kellam merged commit a6c7695 into sourcebot-dev:main Aug 4, 2026
9 checks passed
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.

[bug] it is not possible to use context:0 ... N

2 participants