santifer/career-ops · error
Missing required field
Error message
Missing required field: ${context}.${key} What it means
_require in generate-cover-letter.mjs asserts that a payload object (e.g. candidate, job, company sections) contains every required key for HTML generation. If the object is missing/null/not-an-object or lacks a key, it throws naming the context (section) and key so the caller knows exactly which payload field to supply.
Solutions
- Add the missing `${context}.${key}` field to your payload before calling the generator.
- Log the whole payload object and compare against the template's _require(...) call list for that context.
- Fix key typos by diffing your payload keys against the expected field names.
- Add a pre-flight validation that checks all required keys for each section before invoking.
Example fix
// before
const payload = { candidate: {name: 'A'}, job: {title: 'Eng'} };
// after
const payload = { candidate: {name: 'A'}, job: {title: 'Eng', company: 'Acme'} }; Defensive patterns
Strategy: type-guard
Validate before calling
function requireKeys(obj, keys, ctx) { for (const k of keys) if (!obj || typeof obj !== 'object' || !(k in obj)) throw new Error(`Missing ${ctx}.${k}`); }
requireKeys(payload.job, ['title','company'], 'job'); Type guard
const hasKeys = (obj, keys) => !!obj && typeof obj === 'object' && keys.every(k => k in obj);
Try / catch
try { generateCoverLetter(payload); } catch (e) { const m = e.message.match(/Missing required field: ([\w.]+)/); if (m) { console.error(`Payload missing: ${m[1]}`); process.exit(2); } throw e; } Prevention
- Keep a single payload-building function that always sets every required key.
- Validate payloads with a schema (or the module's own _require list) before calling.
- Diff payload keys against the template's required fields after any template update.
- Watch for typos between payload key names and the documented field names.
When it happens
Trigger: Calling the cover-letter generator with a payload missing a required field, e.g. { candidate: {...}, job: { title } } without job.company; passing null/undefined for a nested section; a typo in a key name (companyName vs company).
Common situations: Hand-written JSON payloads for the module API; a script building the payload conditionally and skipping an optional-looking field that is actually required; schema drift after a template update added a new required key.
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
- apify: entry missing 'actor' (e.g. misceres/indeed-scraper)
- jibeapply: careers_url required
- local-parser: parser.command is required
- 4dayweek: invalid URL
- 4dayweek: URL must use HTTPS
AI-assisted analysis of santifer/career-ops@aac998c7ed (2026-09-16).
Data as JSON: /api/errors/111392dbe5e60ab7.
Report an issue: GitHub.
Appendix: source
Thrown at generate-cover-letter.mjs:78
? posix.slice("output/".length)
: posix;
const candidate = resolve(OUTPUT_ROOT, relativeToRoot);
if (containedInOutput(candidate)) return candidate;
throw new Error(`Refusing to write the cover letter outside output/: ${raw}`);
}
/** True when absPath is a file (not output/ itself) still inside OUTPUT_ROOT. */
function containedInOutput(absPath) {
const rel = relative(OUTPUT_ROOT, absPath);
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
}
/** Assert that a payload object contains the required keys. */
function _require(obj, keys, context) {
for (const key of keys) {
if (!obj || typeof obj !== "object" || !(key in obj)) {
throw new Error(`Missing required field: ${context}.${key}`);
}
}
}
/** Escape user-provided text before inserting it into generated HTML. */
function escapeHtml(text) {
if (!text) return "";
return String(text)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
/** Add an HTTPS scheme to a profile URL when it is omitted. */
function asUrl(value) {
return /^https?:\/\//i.test(value) ? value : `https://${value}`;View on GitHub (pinned to aac998c7ed)