affaan-m/ECC · error · Error

--now must be a valid timestamp

Error message

--now must be a valid timestamp

What it means

getNow in scripts/loop-status.js resolves the --now override into a Date. Numeric strings are treated as epoch milliseconds; anything else is handed to the Date constructor. If the resulting Date is NaN (unparseable timestamp), the script throws '--now must be a valid timestamp' so downstream age/status computations never see an invalid clock.

Solutions

  1. Pass epoch milliseconds: `--now 1735689600000`.
  2. Use an ISO 8601 string: `--now 2026-01-01T12:00:00Z`.
  3. Validate the timestamp in your wrapper first, e.g. `node -e "new Date(process.argv[1])"` or `date -d` to sanity-check.
  4. If generating the value in a script, use `Date.now()` or `new Date().toISOString()` instead of hand-built strings.

Example fix

// before
node scripts/loop-status.js --now 'yesterday maybe'
// after
node scripts/loop-status.js --now "$(date +%s)000"
Defensive patterns

Strategy: validation

Validate before calling

function isValidTimestamp(v){ return /^\d+$/.test(String(v)) || !Number.isNaN(new Date(v).getTime()); }
if (!isValidTimestamp(nowValue)) throw new Error('invalid --now');

Type guard

const isValidDate = (v) => !Number.isNaN(new Date(v).getTime());

Try / catch

try { run(args); } catch (e) { if (e.message.includes('--now')) { console.error('Use epoch ms or ISO 8601 for --now'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Running `node scripts/loop-status.js --now 'not-a-date'`, `--now 2026-13-45` (invalid month/day), or an empty --now value.

Common situations: Hand-editing timestamps in shell scripts, timezone-related malformed strings, passing a formatted date that Date cannot parse in the local runtime, or shell quoting stripping the value.

Related errors


AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16). Data as JSON: /api/errors/cf07b2b620ab36ef. Report an issue: GitHub.

Appendix: source

Thrown at scripts/loop-status.js:167

    return path.resolve(options.home);
  }
  return process.env.HOME || process.env.USERPROFILE || os.homedir();
}

function getNow(options = {}) {
  if (!options.now) {
    return new Date();
  }

  if (options.now === 'now') {
    return new Date();
  }

  const now = /^\d+$/.test(String(options.now))
    ? new Date(Number(options.now))
    : new Date(options.now);
  if (Number.isNaN(now.getTime())) {
    throw new Error('--now must be a valid timestamp');
  }
  return now;
}

function walkJsonlFiles(dir, result = { errors: [], files: [] }) {
  if (!fs.existsSync(dir)) {
    return result;
  }

  let entries;
  try {
    entries = fs.readdirSync(dir, { withFileTypes: true });
  } catch (error) {
    result.errors.push({
      code: error.code || null,
      message: error.message,
      transcriptPath: dir,
    });

View on GitHub (pinned to 8321021c54)