Zoekt: Fix exception when no repository exists
What does this MR do and why?
This MR handles the cases when we don't have a Zoekt repository record better. Instead of rendering an 500, we'd display a nice error message.
Duo summary:
This change addresses a potential issue with the Zoekt search functionality. Previously, the code assumed that
zoekt_nodes.firstwould always return a valid node, but now it safely handles the case where it might be nil by using the safe navigation operator (&.id). Additionally, the failure detection logic has been enhanced to consider a search as failed not only when there's an error, but also when the node ID is missing. These changes make the search functionality more robust by properly handling edge cases where Zoekt nodes might not be available.
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
- Zoekt: Indices have missing repo records (#524348 - closed)
- Add proper 'Search has failed' screen for zoek... (#524388 - closed)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
| Before | After |
|---|---|
![]() |
![]() |
How to set up and validate locally
- Enable Zoekt
- In rails console mark a repo for deletion
Search::Zoekt::Repository.where(project_id: 7).update_all(state: :pending_deletion) - Wait until it's deleted
- Perform a Zoekt search against this project (
flightjs, for example)

