pbakaus/impeccable · error · Error

--now must be a valid date.

Error message

--now must be a valid date.

What it means

Thrown by sheriff.mjs parseArgs when the --now value cannot be parsed into a valid Date (Date.getTime() returns NaN). The --now flag overrides the current time for stale-PR calculations, so an invalid date would break every comparison.

Source

Thrown at scripts/github/sheriff.mjs:455

    else if (arg === '--maintainers') options.maintainers = splitList(requireValue(argv, ++i, arg));
    else if (arg === '--regular-contributors') options.regularContributors = splitList(requireValue(argv, ++i, arg));
    else if (arg === '--exempt-labels') options.exemptLabels = splitList(requireValue(argv, ++i, arg));
    else if (arg === '--now') options.now = new Date(requireValue(argv, ++i, arg));
    else if (arg === '--help' || arg === '-h') {
      printHelp();
      process.exit(0);
    } else {
      throw new Error(`Unknown argument: ${arg}`);
    }
  }

  if (!Number.isFinite(options.warningDays) || options.warningDays < 0) {
    throw new Error('--warning-days must be a non-negative number.');
  }
  if (!Number.isFinite(options.closeDays) || options.closeDays < options.warningDays) {
    throw new Error('--close-days must be at least --warning-days.');
  }
  if (Number.isNaN(options.now.getTime())) throw new Error('--now must be a valid date.');

  return options;
}

function latestMaintainerWaitCommand(pr, maintainers) {
  return latestDate([
    ...(pr.comments || [])
      .filter((comment) => maintainers.has(normalizeLogin(comment.authorLogin)))
      .filter((comment) => hasSheriffWaitCommand(comment.body))
      .map((comment) => comment.createdAt),
    ...(pr.reviews || [])
      .filter((review) => maintainers.has(normalizeLogin(review.authorLogin)))
      .filter((review) => hasSheriffWaitCommand(review.body))
      .map((review) => review.submittedAt),
  ]);
}

function currentDraftStartedAt(pr) {

View on GitHub (pinned to d14711ae3d)

Solutions

  1. Pass an ISO 8601 string: `--now 2025-08-12T00:00:00Z`.
  2. If overriding for tests, generate the date programmatically to avoid format errors.
  3. Leave --now unset to use the real current time.

Example fix

# before
node sheriff.mjs --now 12/08/2025

# after
node sheriff.mjs --now 2025-08-12T00:00:00Z
Defensive patterns

Strategy: validation

Validate before calling

function isValidNow(value) {
  if (!value) return true; // unset uses real now
  const d = new Date(value);
  return !Number.isNaN(d.getTime());
}

Type guard

function isParsableDate(value) {
  return !Number.isNaN(new Date(value).getTime());
}

Try / catch

if (nowArg && !isParsableDate(nowArg)) {
  console.error('--now must be a valid date.');
  process.exit(2);
}

Prevention

When it happens

Trigger: Passing `--now not-a-date`, `--now 2025-13-99`, or any string the Date constructor cannot parse into a real instant.

Common situations: Date format mismatch (e.g. locale-specific string), a typo, or piping an empty variable into --now.

Related errors


AI-assisted analysis of pbakaus/impeccable@d14711ae3d (2026-08-13). Data as JSON: /api/errors/aa1f187e4f75bfd5. Report an issue: GitHub.