fix: handle invalid search query validation errors#4984
Conversation
Signed-off-by: Tanishq Meshram <tnshqmeshram@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
Summary by CodeRabbit
WalkthroughAdds an optional ChangesRepositoryCard updatedAt display
Algolia 400 error graceful handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 4❌ Failed checks (3 warnings, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
2 issues found and verified against the latest diff
Confidence score: 3/5
- In
frontend/src/server/fetchAlgoliaData.ts, non-invalid 400 responses appear to bypass the prior generic error handling and can surface raw backend messages to users, which is a user-facing regression versus the stated behavior—restore the generic fallback path for all non-invalid-query errors before merging. - In
frontend/src/server/fetchAlgoliaData.ts, invalid-query handling relies on matching backend error text, so a wording change could silently break detection and reintroduce incorrect messaging—switch to a stable backend error code/field signal (and add a targeted test) to de-risk this path.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="frontend/src/server/fetchAlgoliaData.ts">
<violation number="1" location="frontend/src/server/fetchAlgoliaData.ts:42">
P2: Invalid-query detection depends on fragile string matching against a backend error message instead of a stable machine-readable error code or field identifier. If the backend wording changes, the fix will regress and the original 'Search service error' toast will reappear.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 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 `@frontend/__tests__/unit/components/RepositoryCard.test.tsx`:
- Around line 76-80: The test suite for RepositoryCard only covers the positive
case where updatedAt is present, but lacks coverage for when updatedAt is
undefined. Add a new test case after the existing "displays repository updated
date when available" test that creates a mock repository with updatedAt
explicitly set to undefined, renders the RepositoryCard component with this
repository, and verifies that the "Updated" text is not present in the document
using queryByText instead of getByText to confirm the conditional rendering
logic handles the undefined case correctly.
In `@frontend/src/components/RepositoryCard.tsx`:
- Around line 90-94: Replace the `div` element in the RepositoryCard component
where the updated date is displayed with a semantic `<time>` element. Add a
`dateTime` attribute to the time element containing the ISO format date string
from details.updatedAt, and keep the displayed text as the human-readable
formatted date using toLocaleDateString(). This improves accessibility and
semantic markup by properly communicating to assistive technologies and search
engines that this is a date value.
- Around line 90-94: Replace the direct date formatting in the RepositoryCard
component with the existing formatDate() utility function. Import formatDate
from frontend/src/utils/dateFormatter.ts and replace the new
Date(details.updatedAt).toLocaleDateString() call with
formatDate(details.updatedAt). This utility already handles invalid date
validation with Number.isNaN() checks, preventing "Invalid Date" from being
displayed to users when malformed date strings are encountered.
In `@frontend/src/server/fetchAlgoliaData.ts`:
- Around line 41-57: There is a duplicate condition block checking for "Invalid
query value" in the errorData error handling logic. The first condition block
(with the identical typeof and includes check) has no body and creates malformed
code. Remove the first incomplete condition block entirely and keep only the
second complete implementation that returns the object with empty hits array and
totalPages set to 0.
- Around line 38-57: The code currently catches "Invalid query value" errors
from Algolia and silently converts them to empty results without any logging. To
improve observability and aid in production debugging, add a log statement
(using console.warn or your preferred logging mechanism) before the return
statement that returns empty results. This log should capture the occurrence of
the invalid query error, ideally including the actual error message from
errorData.error, so that the pattern of invalid queries can be monitored and
analyzed in production environments.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 05d75fe3-b26e-4ce7-a63d-0f3f5270f3e5
📒 Files selected for processing (6)
frontend/__tests__/a11y/components/RepositoryCard.a11y.test.tsxfrontend/__tests__/unit/components/RepositoryCard.test.tsxfrontend/src/components/RepositoryCard.tsxfrontend/src/server/fetchAlgoliaData.tsfrontend/src/server/queries/organizationQueries.tsfrontend/src/types/project.ts
There was a problem hiding this comment.
2 issues found across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.
Re-trigger cubic
|
I noticed this branch currently contains both the repository updated-date feature and the invalid query handling fix. If you'd prefer these to be split into separate PRs for review, I'm happy to separate them. |
|
I'll be happy to make edits if needed ? |
|



Summary
Fixes member search behavior when users enter queries containing unsupported special characters such as '@'
Previously, these queries caused the backend validator to return HTTP 400, which surfaced a "Search service error" notification in the UI.
This change handles the specific invalid query validation error and returns an empty result set instead, allowing the existing "No Users found" state to be displayed.
Changes
Testing
Verified that:
@displays "No Users found"Closes #4979