affaan-m/ECC · warning · Error

--now must be a valid timestamp

Error message

--now must be a valid timestamp

What it means

getNow parses the --now value: the literal 'now' and an unset value both yield new Date(); an all-digit value is treated as an epoch milliseconds timestamp; anything else is handed to the Date constructor. If the resulting date is Invalid Date (getTime() is NaN), the script throws. It is the single source of truth for 'now' across the status computation, used to classify session recency.

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 01e15490f0)

Solutions

  1. Use `--now now` for current time, or omit --now entirely.
  2. Use an ISO 8601 UTC string: `--now 2025-08-12T10:30:00.000Z`.
  3. For epoch, pass milliseconds (13 digits): `--now 1723459800000`.
  4. Quote any string with punctuation to avoid shell splitting.

Example fix

# before
node scripts/loop-status.js --now '2025-08-12 10:30'

# after
node scripts/loop-status.js --now '2025-08-12T10:30:00.000Z'
Defensive patterns

Strategy: validation

Validate before calling

// Validate --now up front: 'now', all-digit (ms epoch), or ISO string parseable to a valid Date.
function isValidNow(v) {
  if (!v || v === 'now') return true;
  if (/^\d+$/.test(String(v))) return Number(v) > 0;
  return !Number.isNaN(new Date(v).getTime());
}

Try / catch

try { parseArgs(process.argv); }
catch (err) { if (/--now must be a valid timestamp/.test(err.message)) { console.error(err.message); printHelp(2); } else throw err; }

Prevention

When it happens

Trigger: Passing a malformed ISO string like `--now 2025-13-40`. Passing a locale-formatted date with spaces/symbols the Date constructor rejects. Passing a non-numeric, non-date string like `--now yesterday`. Passing a numeric with units like `--now 1700000000s`.

Common situations: Pasting a date from a log without quoting or normalizing. Mixing epoch-seconds and epoch-milliseconds (the script assumes milliseconds for all-digit input, so seconds-sized values point to 1970 but still parse — they will not throw, but are wrong; only truly unparseable strings throw).

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/cf07b2b620ab36ef. Report an issue: GitHub.