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.first would 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.

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
image image

How to set up and validate locally

  1. Enable Zoekt
  2. In rails console mark a repo for deletion
    Search::Zoekt::Repository.where(project_id: 7).update_all(state: :pending_deletion)
  3. Wait until it's deleted
  4. Perform a Zoekt search against this project (flightjs, for example)
Edited by Dmitry Gruzd

Merge request reports

Loading