Wrap keyword search in try/catch for resilience

Failed keywords log the error and continue to the next one.
Not marked complete, so they'll be retried on next run.
Also await async onPage callback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 22:14:28 -08:00
parent c35cdfba2c
commit 2e61854be5

View File

@@ -40,6 +40,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
} }
await page.waitForTimeout(PAGE_LOAD_WAIT); await page.waitForTimeout(PAGE_LOAD_WAIT);
try {
let pageNum = 0; let pageNum = 0;
while (pageNum < LINKEDIN_MAX_SEARCH_PAGES) { while (pageNum < LINKEDIN_MAX_SEARCH_PAGES) {
// Scroll to load all cards // Scroll to load all cards
@@ -129,7 +130,7 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
jobs.push(job); jobs.push(job);
} }
if (pageJobs.length > 0 && callbacks.onPage) callbacks.onPage(pageJobs); if (pageJobs.length > 0 && callbacks.onPage) await callbacks.onPage(pageJobs);
const nextBtn = await page.$('button[aria-label="View next page"]'); const nextBtn = await page.$('button[aria-label="View next page"]');
if (!nextBtn) break; if (!nextBtn) break;
@@ -137,6 +138,11 @@ export async function searchLinkedIn(page, search, { onPage, onKeyword } = {}) {
await page.waitForTimeout(PAGE_LOAD_WAIT); await page.waitForTimeout(PAGE_LOAD_WAIT);
pageNum++; pageNum++;
} }
} catch (kwErr) {
console.error(` ❌ Keyword "${keyword}" failed: ${kwErr.message}`);
// Don't mark as complete — will be retried on next run
continue;
}
// Mark keyword complete after all its pages are done // Mark keyword complete after all its pages are done
callbacks.onKeyword?.(ki); callbacks.onKeyword?.(ki);
} }