🔧 Improve search worker initialization and logging for better error handling and debugging

This commit is contained in:
2026-01-28 21:07:19 +00:00
parent 74893f7f74
commit 109a3f1995

View File

@@ -431,7 +431,10 @@ const initSearchWorker = () => {
const handleSearchWorkerMessage = event => { const handleSearchWorkerMessage = event => {
const { type, id, results, percent, error: workerError } = event.data; const { type, id, results, percent, error: workerError } = event.data;
console.log('📨 Worker message received:', type, { percent, resultCount: results?.length }); console.log('📨 Worker message received:', type, {
percent,
resultCount: results?.length
});
if (type === 'progress') { if (type === 'progress') {
operationProgress.value.percent = percent; operationProgress.value.percent = percent;
@@ -660,8 +663,16 @@ const onSearchInput = debounce(async () => {
// Initialize worker if needed // Initialize worker if needed
initSearchWorker(); initSearchWorker();
if (!searchWorker) {
console.error('❌ Worker failed to initialize');
operationProgress.value.active = false;
operationProgress.value.message = 'Worker failed to initialize';
return;
}
// Show progress for long searches // Show progress for long searches
const searchTerm = searchQuery.value.toLowerCase(); const searchTerm = searchQuery.value.toLowerCase();
console.log('🔍 Starting worker search for:', searchTerm);
operationProgress.value = { operationProgress.value = {
active: true, active: true,
percent: 0, percent: 0,
@@ -673,6 +684,12 @@ const onSearchInput = debounce(async () => {
searchWorkerRequestId++; searchWorkerRequestId++;
const requestId = searchWorkerRequestId; const requestId = searchWorkerRequestId;
console.log('📤 Posting message to worker:', {
linesCount: fileLines.value.length,
searchTerm,
requestId
});
searchWorker.postMessage({ searchWorker.postMessage({
lines: fileLines.value, lines: fileLines.value,
searchTerm: searchTerm, searchTerm: searchTerm,