Commit fcfe418a93e2

Vincent Demeester <vincent@sbr.pm>
2026-02-16 15:07:58
Improve fallback messaging and error logging
**Better error logging:** - SearXNG errors now show as warnings, not errors - Only show stack trace in debug mode - Clearer message about fallback **Better user messaging:** - Explain when SearXNG is unavailable - Inform about DuckDuckGo API limitations - Suggest more specific searches **Why DuckDuckGo has limited results:** DuckDuckGo Instant Answer API only works for specific queries (weather, calculator, facts), not general web search. This is why 'typescript best practices' returns 0 results. **Solution:** Use SearXNG (search.sbr.pm) which aggregates multiple search engines and provides comprehensive results. Current 502 error needs infrastructure fix. Now users get helpful feedback instead of just 'No results found'.
Changed files (1)
src
src/pi/tools/websearch.ts
@@ -56,8 +56,11 @@ async function searchSearXNG(query: string, maxResults: number = 5, baseUrl?: st
 
     return results;
   } catch (error) {
-    console.error("SearXNG search error:", error);
-    // Fall back to DuckDuckGo
+    // SearXNG unavailable - this is expected if instance is down
+    if (process.env.DANEEL_DEBUG) {
+      const msg = error instanceof Error ? error.message : String(error);
+      console.warn(`[SearXNG] Unavailable (${msg}), falling back to DuckDuckGo`);
+    }
     return [];
   }
 }
@@ -172,11 +175,20 @@ export const webSearchTool: AgentTool = {
     }
 
     if (results.length === 0) {
+      let message = `No results found for: "${query}"`;
+      
+      // If SearXNG is configured but we're using DuckDuckGo, explain why
+      if (process.env.SEARXNG_URL && searchEngine === "DuckDuckGo") {
+        message += `\n\nNote: SearXNG (${process.env.SEARXNG_URL}) is currently unavailable. The DuckDuckGo fallback has limited coverage for general queries. Please try a more specific search or wait for SearXNG to be available.`;
+      } else if (searchEngine === "DuckDuckGo") {
+        message += `\n\nNote: The DuckDuckGo API has limited coverage for general queries. Try a more specific search term.`;
+      }
+      
       return {
         content: [
           {
             type: "text" as const,
-            text: `No results found for: "${query}"`,
+            text: message,
           },
         ],
         details: { query, resultCount: 0, searchEngine },