santifer/career-ops · error

--from and --to must both be supplied together (or neither…

Error message

--from and --to must both be supplied together (or neither, to use the default current-week range).

What it means

computeWeeklyDigest() in weekly-digest.mjs validates its optional from/to date-range arguments as a pair. Supplying exactly one of --from or --to (leaving the other undefined) throws this error, because a half-specified range is ambiguous. Passing neither uses the default current-week range; passing both is validated separately.

Solutions

  1. Pass both --from and --to together: node weekly-digest.mjs --from 2026-09-07 --to 2026-09-13
  2. Pass neither to use the default current-week range
  3. Fix the calling wrapper so both bounds are computed/passed or both omitted

Example fix

// before
computeWeeklyDigest({ from: '2026-09-07' });
// after
computeWeeklyDigest({ from: '2026-09-07', to: '2026-09-13' });
Defensive patterns

Strategy: validation

Validate before calling

if ((opts.from === undefined) !== (opts.to === undefined)) {
  throw new Error('--from and --to must both be supplied together (or neither)');
}

Type guard

const hasRange = (o) => (o.from !== undefined && o.to !== undefined) || (o.from === undefined && o.to === undefined);

Try / catch

try {
  const digest = computeWeeklyDigest(opts);
} catch (err) {
  if (err.message.includes('must both be supplied together')) {
    console.error(`${err.message}\nExample: --from 2026-09-07 --to 2026-09-13`);
    process.exit(2);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling computeWeeklyDigest({from}) or computeWeeklyDigest({to}) with only one bound, or the CLI invoked with --from but no --to (or vice versa).

Common situations: Scripting the digest with a variable start date but forgetting the end date; editing a command to remove one of the two flags; a wrapper passing null/undefined for just one bound.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at weekly-digest.mjs:316

 */
export function computeWeeklyDigest({
  from,
  to,
  sessionsDir = DEFAULT_SESSIONS_DIR,
  questionBankPath = DEFAULT_QUESTION_BANK_PATH,
} = {}) {
  // Range resolution has three cases, not two:
  //   - neither --from nor --to given -> default current-week range (unchanged)
  //   - exactly one of --from/--to given -> ambiguous, hard error (was:
  //     silently fell back to the default range, which quietly discarded
  //     the one bound the caller did supply)
  //   - both given but from > to -> hard error (was: silently returned an
  //     empty digest, indistinguishable from "no interviews this week")
  let range;
  if (from === undefined && to === undefined) {
    range = computeDefaultRange();
  } else if (from === undefined || to === undefined) {
    throw new Error('--from and --to must both be supplied together (or neither, to use the default current-week range).');
  } else if (from > to) {
    throw new Error(`--from (${from}) must not be after --to (${to}).`);
  } else {
    range = { from, to };
  }

  const allSessions = loadSessions(sessionsDir);
  const sessionsInRange = allSessions.filter((s) => inRange(s.date, range.from, range.to));

  const companyNames = [...new Set(sessionsInRange.map((s) => s.company))];
  // "File exists" and "file has usable content" are independent questions —
  // an existing-but-empty question-bank.md is a different state than a
  // missing one, and the metadata (and printSummary's "present but
  // unmatched" branch) needs to be able to tell them apart.
  const questionBankFound = existsSync(questionBankPath);
  // existsSync() succeeding doesn't guarantee readFileSync() will: the path
  // could be a directory, permissions could block the read, or the file
  // could be deleted between the two calls (TOCTOU). Any of those is an

View on GitHub (pinned to aac998c7ed)