{"record":{"id":"79d96999d1394cd0","repo":"jackwener/OpenCLI","slug":"weibo-user-posts-start-must-be-end","errorCode":null,"errorMessage":"weibo user-posts start must be <= end","messagePattern":"weibo user-posts start must be <= end","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/weibo/user-posts.js","lineNumber":58,"sourceCode":"\nfunction formatShanghaiDate(date) {\n    const parts = new Intl.DateTimeFormat('en-CA', {\n        timeZone: 'Asia/Shanghai',\n        year: 'numeric',\n        month: '2-digit',\n        day: '2-digit',\n    }).formatToParts(date);\n    const get = (type) => parts.find((part) => part.type === type)?.value;\n    return `${get('year')}-${get('month')}-${get('day')}`;\n}\n\nfunction dateToTimestamp(date) {\n    return Math.floor(new Date(`${date}T00:00:00+08:00`).getTime() / 1000);\n}\n\nfunction validateRange(start, end) {\n    if (start && end && dateToTimestamp(start) > dateToTimestamp(end)) {\n        throw new ArgumentError('weibo user-posts start must be <= end');\n    }\n}\n\nfunction mapError(error) {\n    const message = String(error ?? '').trim();\n    if (!message) {\n        throw new CommandExecutionError('weibo user-posts failed without an error message');\n    }\n    if (/login|cookie|登录|auth|forbidden|permission|权限|unauthorized/i.test(message)) {\n        throw new AuthRequiredError('weibo.com', message);\n    }\n    throw new CommandExecutionError(message);\n}\n\nexport const testInternals = {\n    readRequiredId,\n    readLimit,\n    readDate,","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weibo/user-posts.js#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"Scripts that compute 'last month' boundaries and swap start/end, users typing dates in reverse order, or refactors that reversed argument order.","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)."],"exampleFix":"// before\n--start 2024-07-01 --end 2024-01-01\n// after\n--start 2024-01-01 --end 2024-07-01","handlingStrategy":"validation","validationCode":"if (start && end && start > end) throw new Error('start must be <= end (ISO dates compare lexicographically)');","typeGuard":"function isOrderedRange(a, b) {\n  return !a || !b || (typeof a === 'string' && typeof b === 'string' && a <= b);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["argument-validation","date-range","cli"],"backgroundTag":"invalid-date-range","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}