jackwener/OpenCLI · error · ArgumentError
weibo user-posts start must be <= end
Error message
weibo user-posts start must be <= end
What it means
validateRange() enforces that when both start and end are supplied, start is not after end, comparing the two as Shanghai-midnight timestamps. If start > end it throws this ArgumentError, since an inverted date range can never match any posts.
Source
Thrown at clis/weibo/user-posts.js:58
function formatShanghaiDate(date) {
const parts = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Asia/Shanghai',
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).formatToParts(date);
const get = (type) => parts.find((part) => part.type === type)?.value;
return `${get('year')}-${get('month')}-${get('day')}`;
}
function dateToTimestamp(date) {
return Math.floor(new Date(`${date}T00:00:00+08:00`).getTime() / 1000);
}
function validateRange(start, end) {
if (start && end && dateToTimestamp(start) > dateToTimestamp(end)) {
throw new ArgumentError('weibo user-posts start must be <= end');
}
}
function mapError(error) {
const message = String(error ?? '').trim();
if (!message) {
throw new CommandExecutionError('weibo user-posts failed without an error message');
}
if (/login|cookie|登录|auth|forbidden|permission|权限|unauthorized/i.test(message)) {
throw new AuthRequiredError('weibo.com', message);
}
throw new CommandExecutionError(message);
}
export const testInternals = {
readRequiredId,
readLimit,
readDate,View on GitHub (pinned to 49907e53dc)
Solutions
- Swap the values so start is the earlier date and end the later one.
- Fix the calling code that assigns the variables out of order.
- Add a pre-call check comparing the two ISO strings lexicographically (ISO dates compare correctly as strings).
Example fix
// before --start 2024-07-01 --end 2024-01-01 // after --start 2024-01-01 --end 2024-07-01
Defensive patterns
Strategy: validation
Validate before calling
if (start && end && start > end) throw new Error('start must be <= end (ISO dates compare lexicographically)'); Type guard
function isOrderedRange(a, b) {
return !a || !b || (typeof a === 'string' && typeof b === 'string' && a <= b);
} Prevention
- Keep start/end in named variables and assert ordering before invocation.
- Never swap argument order when wrapping the CLI in a function.
- Compare ISO strings directly — they sort chronologically.
When it happens
Trigger: Invoking the command with start later than end, e.g. start='2024-06-01', end='2024-01-01', or variables accidentally swapped in a calling script.
Common situations: Scripts that compute 'last month' boundaries and swap start/end, users typing dates in reverse order, or refactors that reversed argument order.
Related errors
- huodongxing date must be <= dateTo
- <train-no> "${trainNo}" does not look like a 12306 internal
- --from station must not be empty
- --to station must not be empty
- --seat-types must contain only 12306 seat letters/digits (A-
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/79d96999d1394cd0.
Report an issue: GitHub.