santifer/career-ops · error · Error

getEmployerProfile: id is required

Error message

getEmployerProfile: id is required

What it means

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.

Source

Thrown at plugins/h1b-sponsor/lib/index.mjs:377

  const q = String(name || '').trim();
  if (q.length < 2) return { total: 0, results: [] };

  const target = normalize(q);
  const page = boundedTop(SEARCH_PAGE);
  let total = 0;
  for await (const rec of readRecords(indexFile(opts))) {
    if (!normalize(rec.n).includes(target)) continue;
    total++;
    page.push(rec);
  }
  // Same order the endpoint pages in, so the one page a broad query shows holds
  // the entities that actually file rather than the ones that sort first.
  return { total, results: page.drain().map(r => ({ id: String(r.k), name: String(r.n) })) };
}

export async function getEmployerProfile(id, opts = {}) {
  const sanitized = String(id || '').trim();
  if (!sanitized) throw new Error('getEmployerProfile: id is required');

  const file = indexFile(opts);
  const memo = seen.get(memoKey(file, sanitized));
  if (memo) return recordToProfile(memo);

  for await (const rec of readRecords(file)) {
    if (String(rec.k) !== sanitized) continue;
    seen.set(memoKey(file, sanitized), rec);
    return recordToProfile(rec);
  }
  // The HTTP path 404s here and reports the same thing: an id that resolves to
  // no employer is unknown, not an employer with zero filings.
  return null;
}

View on GitHub (pinned to 1696bec4d0)

Solutions

  1. Pass the employer id string (or EIN) from a prior search result, not a whole record object.
  2. Guard the call site: skip or raise a contextual error when the id is missing before invoking.
  3. Confirm the previous lookup actually matched — search by exact name or EIN and check its result is non-empty.

Example fix

// before
const profile = await getEmployerProfile(match); // match may be undefined
// after
if (!match?.id) throw new Error(`No index match for employer ${name}`);
const profile = await getEmployerProfile(String(match.id));
Defensive patterns

Strategy: type-guard

Validate before calling

function hasEmployerId(x) {
  return (typeof x === 'string' || typeof x === 'number') && String(x).trim() !== '';
}
// before calling: if (!hasEmployerId(rec?.id)) skip this record;

Type guard

function isIndexRecordWithId(r) {
  return r != null && typeof r === 'object' &&
    (typeof r.id === 'string' || typeof r.id === 'number') &&
    String(r.id).trim() !== '';
}

Try / catch

try {
  const profile = await getEmployerProfile(id);
} catch (e) {
  if (e.message === 'getEmployerProfile: id is required') {
    console.warn('Skipping employer: index lookup produced no id.');
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of santifer/career-ops@1696bec4d0 (2026-09-01). Data as JSON: /api/errors/ba643ddb0aa689ec. Report an issue: GitHub.