{"record":{"id":"f757874a6eff9c0c","repo":"santifer/career-ops","slug":"vc-portfolios-yc-api-fetch-failed-err-message","errorCode":null,"errorMessage":"vc-portfolios: YC API fetch failed — ${err.message}","messagePattern":"vc-portfolios: YC API fetch failed — (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"seeds/vc-portfolios.mjs","lineNumber":347,"sourceCode":" */\nexport async function fetchYCCompanies({ timeoutMs = DEFAULT_TIMEOUT_MS, maxPages = YC_MAX_PAGES } = {}) {\n  /** @type {SeedCompany[]} */\n  const all = [];\n  const seen = new Set();\n\n  // YC_MAX_PAGES is a hard ceiling: clamp here so an explicit maxPages (or a\n  // stray Infinity) can never spin the walk past the runaway guard.\n  const limit = Math.min(maxPages, YC_MAX_PAGES);\n\n  let page = 1;\n  for (let fetched = 0; fetched < limit; fetched++) {\n    const url = `https://api.ycombinator.com/v0.1/companies?page=${page}&per_page=1000`;\n    let payload;\n    try {\n      const res = await fetchWithTimeout(url, { timeoutMs });\n      payload = await res.json();\n    } catch (err) {\n      if (page === 1) throw new Error(`vc-portfolios: YC API fetch failed — ${err.message}`);\n      break; // Partial data is fine after page 1.\n    }\n\n    const entries = parseYCPayload(payload);\n    if (entries.length === 0) break; // No more companies.\n\n    for (const e of entries) {\n      if (!seen.has(e.slug)) {\n        seen.add(e.slug);\n        all.push(e);\n      }\n    }\n\n    // The API caps page size server-side (~30/page; per_page is ignored) and\n    // reports totalPages — follow its signal instead of guessing from batch size.\n    const raw = /** @type {any} */ (payload);\n    if (Number.isInteger(raw?.totalPages) && raw.totalPages > 0) {\n      if (page >= raw.totalPages) break;","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/santifer/career-ops/blob/9b17a8ac97b398a496b38e423ae24e433b43254f/seeds/vc-portfolios.mjs#L329-L365","documentation":"fetchYCCompanies() walks the YC API page by page. If the very first page (page=1) fetch fails — wrapping the underlying fetchWithTimeout error — it throws an Error, because no data at all could be obtained. Failures on subsequent pages (page > 1) are tolerated as partial data (the loop breaks). This balances robustness (partial progress is useful) with fail-fast on total inability to reach the source.","triggerScenarios":"The YC API (api.ycombinator.com) is unreachable, returns non-2xx on the first page, or the abort timeout fires before the first response completes. Network outage, DNS failure, or a blocking firewall on page 1.","commonSituations":"Offline or behind a corporate firewall blocking api.ycombinator.com; a transient outage during a seed scan; a too-aggressive timeoutMs that aborts the large first page (per_page=1000).","solutions":["Verify connectivity: curl -I https://api.ycombinator.com/v0.1/companies?page=1&per_page=1000.","Increase the timeout: pass a larger timeoutMs to fetchYCCompanies (default DEFAULT_TIMEOUT_MS).","Retry the scan later if the YC API is having a transient outage.","If behind a proxy, ensure HTTPS_PROXY / fetch agent is configured."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  companies = await fetchYCCompanies({ timeoutMs });\n} catch (err) {\n  if (err.message.includes('YC API fetch failed')) {\n    console.error(`YC seed unavailable: ${err.message}. Continuing without YC.`);\n    companies = [];\n  } else throw err;\n}","preventionTips":["Treat seed fetch failures as non-fatal in a multi-seed scan — skip the failing seed and continue with others.","Increase timeoutMs for the large first page (per_page=1000).","Verify api.ycombinator.com reachability in your network before relying on the YC seed."],"tags":["network","seeds","vc-portfolios","yc-api","fetch"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}