fix(SEC-REVIEW-1): Surface search errors in LinkAutocomplete
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Previously the catch block in searchEntries silently swallowed all non-abort errors, showing "No entries found" when the search actually failed. This misled users into thinking the knowledge base was empty. - Add searchError state variable - Set PDA-friendly error message on non-abort failures - Clear error state on subsequent successful searches - Render error in amber (distinct from gray "No entries found") - Add 3 tests: error display, error clearing, abort exclusion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,7 @@ export function LinkAutocomplete({
|
||||
const [results, setResults] = useState<SearchResult[]>([]);
|
||||
const [selectedIndex, setSelectedIndex] = useState<number>(0);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [searchError, setSearchError] = useState<string | null>(null);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const searchTimeoutRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
@@ -88,6 +89,7 @@ export function LinkAutocomplete({
|
||||
|
||||
setResults(searchResults);
|
||||
setSelectedIndex(0);
|
||||
setSearchError(null);
|
||||
} catch (error) {
|
||||
// Ignore aborted requests - a newer search has superseded this one
|
||||
if (error instanceof DOMException && error.name === "AbortError") {
|
||||
@@ -95,6 +97,7 @@ export function LinkAutocomplete({
|
||||
}
|
||||
console.error("Failed to search entries:", error);
|
||||
setResults([]);
|
||||
setSearchError("Search unavailable — please try again");
|
||||
} finally {
|
||||
if (!signal.aborted) {
|
||||
setIsLoading(false);
|
||||
@@ -371,6 +374,8 @@ export function LinkAutocomplete({
|
||||
>
|
||||
{isLoading ? (
|
||||
<div className="p-3 text-sm text-gray-500 dark:text-gray-400">Searching...</div>
|
||||
) : searchError ? (
|
||||
<div className="p-3 text-sm text-amber-600 dark:text-amber-400">{searchError}</div>
|
||||
) : results.length === 0 ? (
|
||||
<div className="p-3 text-sm text-gray-500 dark:text-gray-400">
|
||||
{state.query ? "No entries found" : "Start typing to search..."}
|
||||
|
||||
Reference in New Issue
Block a user