Skip to content

Commit ca79df3

Browse files
Sladucaclaude
andauthored
fix: validate -s/--start flag and error on unparseable values (#259)
* fix: validate --start flag input and error on unparseable values Previously, passing an invalid string to -s/--start (e.g. a typo or free-form text) would silently fall back to NOW via chrono-node's parseDate returning null. The command would then proceed as if no start time was specified. Now the argParser throws a CommanderError with a clear message when the input cannot be parsed as a date. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix error message --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 101ad1e commit ca79df3

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/lib/nodes/utils.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import utc from "dayjs/plugin/utc.js";
99
import { parseDurationArgument } from "../../helpers/duration.ts";
1010
import { logAndQuit } from "../../helpers/errors.ts";
1111
import { formatNullableDateRange } from "../../helpers/format-time.ts";
12-
import { parseStartDateOrNow } from "../../helpers/units.ts";
1312

1413
dayjs.extend(utc);
1514
dayjs.extend(timezone);
@@ -330,11 +329,23 @@ export const maxPriceOption = new Option(
330329
/**
331330
* Common --start option using same parser as buy command
332331
*/
332+
function parseStartDateOrNowOrThrow(val: string): Date | "NOW" {
333+
const nowRe = /\b(?:"|')?[nN][oO][wW](?:"|')?\b/;
334+
if (nowRe.test(val)) return "NOW";
335+
const chronoDate = parseDate(val);
336+
if (!chronoDate) {
337+
logAndQuit(
338+
`Invalid start time: "${val}". Use ISO 8601 format (e.g. '2024-01-15T10:00:00Z'), a relative time (e.g. '+1h'), or 'NOW'.`,
339+
);
340+
}
341+
return chronoDate;
342+
}
343+
333344
export const startOrNowOption = new Option(
334345
"-s, --start <start>",
335346
"Start time (ISO 8601 format:'2022-10-27T14:30:00Z' or relative time like '+1d', or 'NOW')",
336347
)
337-
.argParser(parseStartDateOrNow)
348+
.argParser(parseStartDateOrNowOrThrow)
338349
.default("NOW" as const);
339350

340351
/**

0 commit comments

Comments
 (0)