{"record":{"id":"1bd665ffa48b1a8e","repo":"jackwener/OpenCLI","slug":"bilibili-comment-label-must-be-a-positive-integ","errorCode":null,"errorMessage":"bilibili comment ${label} must be a positive integer","messagePattern":"bilibili comment (.+?) must be a positive integer","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/comment.js","lineNumber":13,"sourceCode":"/**\n * Bilibili comment — posts a top-level comment or a reply on a video via the official API.\n * Uses /x/v2/reply/add, authenticated by the logged-in cookie + bili_jct CSRF token.\n * @username mentions in the message are resolved to real mentions (at_name_to_mid).\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { apiGet, apiPost, requireOkPayload, resolveBvid, resolveUid } from './utils.js';\n\nfunction readPositiveInteger(value, label) {\n    const n = Number(value);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(`bilibili comment ${label} must be a positive integer`);\n    }\n    return n;\n}\n\ncli({\n    site: 'bilibili',\n    name: 'comment',\n    access: 'write',\n    description: '在 B站视频下发表评论或回复（官方 API，需登录；消息里的 @用户 会被解析为真实提及）',\n    domain: 'www.bilibili.com',\n    strategy: Strategy.COOKIE,\n    args: [\n        { name: 'bvid', required: true, positional: true, help: 'Video BV ID / URL / b23.tv short link' },\n        { name: 'message', required: true, positional: true, help: 'Comment text. Any @username in it is resolved to a real mention' },\n        { name: 'parent', type: 'int', help: 'top-level/root rpid to reply under (omit for a top-level comment)' },\n        { name: 'execute', type: 'boolean', help: 'Actually post the comment. Without it the command refuses to write.' },\n    ],\n    columns: ['rpid', 'bvid', 'oid', 'message', 'url'],","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/comment.js#L1-L31","documentation":"readPositiveInteger strictly validates comment-related numeric arguments (parent rpid). It throws ArgumentError when the value is not an integer or is <= 0, preventing malformed ids from reaching the Bilibili reply API.","triggerScenarios":"Passing --parent as a non-numeric string (e.g. 'abc'), a float (e.g. '1.5'), zero, or a negative number to bilibili comment subcommands that resolve a parent comment id.","commonSituations":"Copy-pasting a URL fragment containing the rpid plus extra characters; passing 0 assuming it means 'no parent'; shell quoting issues splitting the value; confusing oid/rpid values.","solutions":["Pass a positive integer rpid, e.g. --parent 123456789012345678","Strip URL fragments/prefixes and quote arguments in the shell","Omit --parent entirely for a top-level comment instead of passing 0","Validate with Number.isInteger(n) && n > 0 in wrapper scripts"],"exampleFix":"// before\ncli comment --parent 0 ...\n// after\ncli comment ...        # top-level: omit --parent\ncli comment --parent 87654321 ...","handlingStrategy":"validation","validationCode":"const n = Number(parentArg);\nif (!Number.isInteger(n) || n <= 0) throw new Error(`parent must be a positive integer, got: ${parentArg}`);","typeGuard":"const isPositiveInt = (v) => Number.isInteger(Number(v)) && Number(v) > 0;","tryCatchPattern":"try { await comment({ parent }); } catch (e) { if (/must be a positive integer/.test(e.message)) { console.error('Fix the --parent value'); } else throw e; }","preventionTips":["Copy bare rpid numbers without surrounding URL text","Omit --parent for top-level comments instead of passing 0","Quote CLI args to avoid shell splitting","Validate inputs in wrapper scripts"],"tags":["argument-validation","input-validation","cli"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}