santifer/career-ops · error · Error

getEmployerProfile: id is required

Error message

getEmployerProfile: id is required

What it means

getEmployerProfile(id) looks up a single employer in the H1B index by its record id. Before doing any I/O it coerces the argument to a string and trims it; if nothing remains it throws, because an empty id can never match a record and proceeding would scan the whole index for nothing. The guard also protects against undefined/null being passed through from upstream search results that were destructured incorrectly.

Solutions

  1. Ensure the caller supplies a real employer id obtained from a prior search() call's results (the id field of {id, name} entries).
  2. Validate the id at the entry point of your handler/route and return a 400 before invoking the library.
  3. If the id comes from user input, trim it and check length > 0; treat whitespace-only as missing.
  4. If upstream data legitimately has blank ids, filter those records out before mapping them to getEmployerProfile calls.

Example fix

// before
const profile = await getEmployerProfile(req.params.id);

// after
const id = (req.params.id || '').trim();
if (!id) return res.status(400).json({ error: 'employer id is required' });
const profile = await getEmployerProfile(id);
Defensive patterns

Strategy: validation

Validate before calling

function requireEmployerId(id) {
  const s = String(id ?? '').trim();
  if (!s) throw new TypeError('employer id is required and must be non-empty');
  return s;
}
// call site:
const profile = await getEmployerProfile(requireEmployerId(inputId));

Type guard

function isEmployerId(v) {
  return (typeof v === 'string' || typeof v === 'number') && String(v).trim().length > 0;
}

Try / catch

try {
  profile = await getEmployerProfile(id);
} catch (e) {
  if (/id is required/.test(e.message)) {
    return respond(400, 'Missing employer id');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getEmployerProfile('') , getEmployerProfile(null), getEmployerProfile(undefined), or getEmployerProfile(' ') — typically when an id field is missing from an API payload, a search result row ({id, name}) lost its id, or a route/query parameter was absent (e.g. req.query.id is undefined).

Common situations: A web handler forwards an empty URL segment (/employer/ → id ''); a frontend renders a detail page before the search result object loads and passes undefined; a data migration or CSV import produced rows with blank employer ids; destructuring a result array in the wrong order so id picks up the name slot's undefined.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: 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 aac998c7ed)