{"record":{"id":"ef02671dedb8c971","repo":"santifer/career-ops","slug":"getemployerprofile-id-is-required","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/api.mjs","lineNumber":547,"sourceCode":"    red_flags: {\n      staffing_shop: staffing\n        ? {\n            value: staffing.value === true,\n            share: typeof staffing.share === 'number' ? staffing.share : null,\n            n_secondary: staffing.n_secondary ?? null,\n            n_total: staffing.n_total ?? null,\n            basis: staffing.basis ?? null,\n          }\n        : null,\n    },\n    employer_name: employer.name ?? null,\n    employer_id: employer.id ?? employer.ein ?? null,\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  const url = `${apiBase()}/employers/${encodeURIComponent(sanitized)}`;\n  const raw = await requestJson(url, opts, { allow404: false });\n  return normalizeProfile(raw);\n}\n","sourceCodeStart":529,"sourceCodeEnd":552,"githubUrl":"https://github.com/santifer/career-ops/blob/1696bec4d021768e7359f9aad6b329cba883da20/plugins/h1b-sponsor/lib/api.mjs#L529-L552","documentation":"getEmployerProfile() in plugins/h1b-sponsor/lib/api.mjs requires a non-empty employer id. It sanitizes the argument with String(id || '').trim() and throws when nothing usable remains, before building the request URL.","triggerScenarios":"Calling getEmployerProfile(undefined), getEmployerProfile(null), getEmployerProfile(''), or getEmployerProfile(0) — any falsy or whitespace-only value — directly against the API-backed client.","commonSituations":"A lookup step returned undefined (company not found in a prior search) and its result was passed straight through; a variable name shadowed/misspelled so the id never got assigned; trimming whitespace-only user input.","solutions":["Ensure the id comes from a successful prior lookup (e.g. a search result's employer id or EIN) before calling getEmployerProfile.","Check the caller: log/inspect the value being passed; guard with `if (!id) return;` or throw a more contextual error upstream.","If the company genuinely has no id, skip the profile call rather than calling it with an empty value."],"exampleFix":"// before\nconst profile = await getEmployerProfile(searchResult?.id);\n// after\nif (!searchResult?.id) throw new Error(`No employer id found for ${companyName}`);\nconst profile = await getEmployerProfile(searchResult.id);","handlingStrategy":"type-guard","validationCode":"function hasEmployerId(x) {\n  return typeof x === 'string' ? x.trim().length > 0 : Boolean(x);\n}\n// before calling: if (!hasEmployerId(candidateId)) skip or raise a contextual error;","typeGuard":"function isNonEmptyId(v) {\n  return (typeof v === 'string' || typeof v === 'number') && String(v).trim() !== '';\n}","tryCatchPattern":"try {\n  const profile = await getEmployerProfile(id);\n} catch (e) {\n  if (e.message === 'getEmployerProfile: id is required') {\n    console.warn(`No employer id available for \"${name}\" — skipping profile lookup.`);\n    return null;\n  }\n  throw e;\n}","preventionTips":["Only call getEmployerProfile with an id obtained from a successful prior search result.","Pass the id field explicitly, never a whole record object.","Guard optional-chained lookups (searchResult?.id) before calling.","Fail fast upstream with a contextual message naming the company, so the empty id is diagnosable."],"tags":["argument-validation","api","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"}