Skip to content

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

Open
rachit367 wants to merge 3 commits into
sourcebot-dev:mainfrom
rachit367:rachit367/fix-search-context-crash
Open

fix(web): return graceful error for unknown search context#1362
rachit367 wants to merge 3 commits into
sourcebot-dev:mainfrom
rachit367:rachit367/fix-search-context-crash

Conversation

@rachit367

@rachit367 rachit367 commented Jun 23, 2026

Copy link
Copy Markdown

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 the appropriate error details.
  • Tests

    • Added test coverage for query parsing to verify the correct error is returned when a search context can’t be found, and that valid contexts expand into their associated repositories.

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14a555b9-9272-4a52-bbd9-cbef0730b3a1

📥 Commits

Reviewing files that changed from the base of the PR and between 2f09e68 and e0ac451.

📒 Files selected for processing (1)
  • CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md

Walkthrough

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

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 assert the rejected missing-context lookup and the successful repo expansion, and 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: returning a graceful error when an unknown search context is requested.
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.

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

✨ 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
{}

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