jackwener/OpenCLI · error · CommandExecutionError
Bilibili ${label} API failed: ${message} (${payload.code})
Error message
Bilibili ${label} API failed: ${message} (${payload.code}) What it means
CommandExecutionError thrown by requireOkPayload when the Bilibili API returns a non-zero code that is not auth-like. The code is the Bilibili API's own error code (e.g. -400 request error, -404 not found, 12061 comment closed) and the message is the API's Chinese-language error text.
Source
Thrown at clis/bilibili/comments.js:45
return null;
}
const parent = Number(value);
if (!Number.isInteger(parent) || parent <= 0) {
throw new ArgumentError('bilibili comments parent must be a positive integer rpid');
}
return parent;
}
function requireOkPayload(payload, label) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload) || !Object.hasOwn(payload, 'code')) {
throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
}
if (payload.code !== 0) {
const message = payload.message ?? 'unknown error';
if (isAuthLikeBilibiliError(payload.code, message)) {
throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);
}
throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);
}
return payload.data;
}
function requireReplies(data, label) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed data`);
}
if (!Object.hasOwn(data, 'replies')) {
throw new CommandExecutionError(`Bilibili ${label} API did not return replies`);
}
if (data.replies === null) {
return [];
}
if (!Array.isArray(data.replies)) {
throw new CommandExecutionError(`Bilibili ${label} API returned malformed replies`);
}
return data.replies;View on GitHub (pinned to 49907e53dc)
Solutions
- Read the code/message in the error to identify the API-level cause
- Verify the bvid resolves to an existing video and comments are enabled
- If --parent was used, confirm the rpid exists and belongs to this video
- Retry later if the code indicates a transient/rate-limit condition
Example fix
// before bilibili comments BV1Deleted000 --parent 123 // code -404 // after bilibili comments BV1WtAGzYEBm // valid video, top-level comments
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
function isBiliApiError(x) { return !!x && typeof x === 'object' && 'code' in x && x.code !== 0; } Try / catch
try { const rows = await run(['bilibili','comments',bvid]); } catch (e) { const m = /API failed: .* \((-?\d+)\)/.exec(e.message); if (m) { const code = Number(m[1]); if (code === -509 || code === -412) return retryWithBackoff(fn); if (code === -404) console.error('video or rpid not found'); } throw e; } Prevention
- Validate the bvid/rpid inputs before calling
- Handle rate-limit codes with backoff, not tight retries
- Check the video exists and comments are enabled before processing
When it happens
Trigger: The view/reply API responds {code: -400, message: '请求错误'} or similar non-zero, non-auth code — e.g. invalid oid/type params, deleted video, comments disabled, or wrong rpid passed as --parent.
Common situations: Deleted or private video; comment section closed by uploader; invalid --parent rpid that no longer exists; Bilibili server-side transient error (code -509 or similar rate-limit codes).
Related errors
- Bilibili ${label} API returned a malformed payload
- Bilibili ${label} API returned malformed data
- Bilibili ${label} API did not return replies
- Bilibili ${label} API returned malformed replies
- coingecko global returned malformed JSON: ${err?.message ??
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/dd3d4e8f428c80b8.
Report an issue: GitHub.