{"record":{"id":"ba643ddb0aa689ec","repo":"santifer/career-ops","slug":"getemployerprofile-id-is-required-ba643d","errorCode":null,"errorMessage":"getEmployerProfile: id is required","messagePattern":"getEmployerProfile: id is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/h1b-sponsor/lib/index.mjs","lineNumber":377,"sourceCode":"  const q = String(name || '').trim();\n  if (q.length < 2) return { total: 0, results: [] };\n\n  const target = normalize(q);\n  const page = boundedTop(SEARCH_PAGE);\n  let total = 0;\n  for await (const rec of readRecords(indexFile(opts))) {\n    if (!normalize(rec.n).includes(target)) continue;\n    total++;\n    page.push(rec);\n  }\n  // Same order the endpoint pages in, so the one page a broad query shows holds\n  // the entities that actually file rather than the ones that sort first.\n  return { total, results: page.drain().map(r => ({ id: String(r.k), name: String(r.n) })) };\n}\n\nexport async function getEmployerProfile(id, opts = {}) {\n  const sanitized = String(id || '').trim();\n  if (!sanitized) throw new Error('getEmployerProfile: id is required');\n\n  const file = indexFile(opts);\n  const memo = seen.get(memoKey(file, sanitized));\n  if (memo) return recordToProfile(memo);\n\n  for await (const rec of readRecords(file)) {\n    if (String(rec.k) !== sanitized) continue;\n    seen.set(memoKey(file, sanitized), rec);\n    return recordToProfile(rec);\n  }\n  // The HTTP path 404s here and reports the same thing: an id that resolves to\n  // no employer is unknown, not an employer with zero filings.\n  return null;\n}\n","sourceCodeStart":359,"sourceCodeEnd":392,"githubUrl":"https://github.com/santifer/career-ops/blob/1696bec4d021768e7359f9aad6b329cba883da20/plugins/h1b-sponsor/lib/index.mjs#L359-L392","documentation":"The index-backed getEmployerProfile() in lib/index.mjs shares the same guard as the API version: the id is sanitized with String(id || '').trim() and an empty result throws. This variant looks the employer up in the local sidecar index instead of making a network call.","triggerScenarios":"Calling the index module's getEmployerProfile with undefined, null, '', '  ', or 0 — typically the id was never populated by an earlier search/lookup step over the index.","commonSituations":"Iterating a results array where some entries lack an id field; passing a record object instead of the id string (e.g. getEmployerProfile(rec) where rec.id was intended); an upstream search returned no match for the company name.","solutions":["Pass the employer id string (or EIN) from a prior search result, not a whole record object.","Guard the call site: skip or raise a contextual error when the id is missing before invoking.","Confirm the previous lookup actually matched — search by exact name or EIN and check its result is non-empty."],"exampleFix":"// before\nconst profile = await getEmployerProfile(match); // match may be undefined\n// after\nif (!match?.id) throw new Error(`No index match for employer ${name}`);\nconst profile = await getEmployerProfile(String(match.id));","handlingStrategy":"type-guard","validationCode":"function hasEmployerId(x) {\n  return (typeof x === 'string' || typeof x === 'number') && String(x).trim() !== '';\n}\n// before calling: if (!hasEmployerId(rec?.id)) skip this record;","typeGuard":"function isIndexRecordWithId(r) {\n  return r != null && typeof r === 'object' &&\n    (typeof r.id === 'string' || typeof r.id === 'number') &&\n    String(r.id).trim() !== '';\n}","tryCatchPattern":"try {\n  const profile = await getEmployerProfile(id);\n} catch (e) {\n  if (e.message === 'getEmployerProfile: id is required') {\n    console.warn('Skipping employer: index lookup produced no id.');\n    return null;\n  }\n  throw e;\n}","preventionTips":["Validate search results before chaining into profile lookups; some matches may lack ids.","Pass String(rec.id), not the record itself.","Handle whitespace-only input as missing (the library trims before checking).","When iterating results, filter to entries with a truthy id first."],"tags":["argument-validation","index","h1b"],"backgroundTag":"missing-required-argument","analyzedSha":"1696bec4d021768e7359f9aad6b329cba883da20","analyzedAt":"2026-09-01T19:19:23.111Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}