fix: add error handling to SearchProviderRegistry #11

Open
opened 2026-02-20 02:38:04 +00:00 by Clotho · 0 comments
Member

Issue

src/Search/SearchProviderRegistry.php lacks error handling when executing provider search methods.

Problem

search() method (lines 105-158)

Current issue:

  • Calls $provider->search($query) without try-catch
  • If a provider throws exception, entire search fails
  • No graceful degradation when one provider fails

Impact:

  • One broken search provider breaks global search
  • No error feedback to user
  • No logging of which provider failed

Required Fix

public function search(string $query, ?Workspace $workspace = null): Collection
{
    $results = collect();

    foreach ($this->providers as $id => $provider) {
        try {
            $providerResults = $provider->search($query);
            
            // Filter by workspace if provided
            if ($workspace) {
                $providerResults = $providerResults->filter(
                    fn($result) => $result->workspaceId === $workspace->id
                );
            }
            
            $results = $results->merge($providerResults);
        } catch (Exception $e) {
            Log::error('Search provider failed', [
                'provider' => $id,
                'query' => $query,
                'error' => $e->getMessage(),
                'trace' => $e->getTraceAsString()
            ]);
            
            // Continue with other providers - graceful degradation
            continue;
        }
    }

    return $results;
}

Benefits

  • Graceful degradation: other providers still work
  • Error logging for debugging
  • Better user experience (partial results vs no results)
  • Identifies problematic providers

Testing Requirements

  • Test with failing provider
  • Verify other providers still execute
  • Test error logging
  • Test with all providers failing

Priority

High - Global search is a core admin feature.

Discovered by

Automatic codebase scan (issue #3)

## Issue `src/Search/SearchProviderRegistry.php` lacks error handling when executing provider search methods. ## Problem ### search() method (lines 105-158) **Current issue:** - Calls `$provider->search($query)` without try-catch - If a provider throws exception, entire search fails - No graceful degradation when one provider fails **Impact:** - One broken search provider breaks global search - No error feedback to user - No logging of which provider failed ## Required Fix ```php public function search(string $query, ?Workspace $workspace = null): Collection { $results = collect(); foreach ($this->providers as $id => $provider) { try { $providerResults = $provider->search($query); // Filter by workspace if provided if ($workspace) { $providerResults = $providerResults->filter( fn($result) => $result->workspaceId === $workspace->id ); } $results = $results->merge($providerResults); } catch (Exception $e) { Log::error('Search provider failed', [ 'provider' => $id, 'query' => $query, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); // Continue with other providers - graceful degradation continue; } } return $results; } ``` ## Benefits - Graceful degradation: other providers still work - Error logging for debugging - Better user experience (partial results vs no results) - Identifies problematic providers ## Testing Requirements - Test with failing provider - Verify other providers still execute - Test error logging - Test with all providers failing ## Priority **High** - Global search is a core admin feature. ## Discovered by Automatic codebase scan (issue #3)
Clotho added the
discovery
label 2026-02-20 02:38:04 +00:00
Charon added
PHP
bug
P1
and removed
discovery
labels 2026-02-20 12:16:54 +00:00
Clotho was assigned by Charon 2026-02-20 12:20:48 +00:00
Charon added the
agent-ready
label 2026-02-21 01:30:23 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: core/php-admin#11
No description provided.