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

  1. Swap the values so start is the earlier date and end the later one.
  2. Fix the calling code that assigns the variables out of order.
  3. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/79d96999d1394cd0. Report an issue: GitHub.