jackwener/OpenCLI · error · CommandExecutionError
${commandName}: malformed comment row at index ${index}
Error message
${commandName}: malformed comment row at index ${index} What it means
Each element of the comments array must be a plain non-null object. Primitives, arrays, or null elements throw this error, which includes the failing index for debugging.
Source
Thrown at clis/xiaohongshu/comments.js:113
if ((parsed.protocol !== 'https:' && parsed.protocol !== 'http:') || parsed.username || parsed.password) {
throw new CommandExecutionError(`${commandName}: malformed comment row image URL`);
}
const href = parsed.toString();
if (!urls.includes(href))
urls.push(href);
}
return urls;
}
export function normalizeCommentRows(value, commandName = 'xiaohongshu/comments') {
if (value == null)
return [];
if (!Array.isArray(value)) {
throw new CommandExecutionError(`${commandName}: malformed comments payload`);
}
return value.map((row, index) => {
if (!row || typeof row !== 'object' || Array.isArray(row)) {
throw new CommandExecutionError(`${commandName}: malformed comment row at index ${index}`);
}
const text = normalizeOptionalString(row.text, 'text', commandName);
if (!text) {
throw new CommandExecutionError(`${commandName}: malformed comment row text`);
}
const likes = Number(row.likes);
if (!Number.isInteger(likes) || likes < 0) {
throw new CommandExecutionError(`${commandName}: malformed comment row likes`);
}
if (typeof row.is_reply !== 'boolean') {
throw new CommandExecutionError(`${commandName}: malformed comment row is_reply`);
}
return {
author: normalizeOptionalString(row.author, 'author', commandName),
authorHrefRaw: normalizeOptionalString(row.authorHrefRaw, 'authorHrefRaw', commandName),
text,
likes,
time: normalizeOptionalString(row.time, 'time', commandName),View on GitHub (pinned to 49907e53dc)
Solutions
- Filter the array before normalizing: rows.filter(r => r && typeof r === 'object' && !Array.isArray(r)).
- Log rows[index] reported in the error to identify the bad element.
- Fix upstream extraction to skip placeholder/deleted comment entries.
- Update the normalizer to silently drop invalid rows if graceful degradation is acceptable.
Example fix
// before normalizeCommentRows(rows, cmd); // after const clean = rows.filter(r => r && typeof r === 'object' && !Array.isArray(r)); normalizeCommentRows(clean, cmd);
Defensive patterns
Strategy: validation
Validate before calling
const clean = (rows ?? []).filter(r => r && typeof r === 'object' && !Array.isArray(r));
if (clean.length !== rows?.length) console.warn(`Dropped ${rows.length - clean.length} invalid comment rows`); Type guard
function isCommentRow(r) {
return Boolean(r) && typeof r === 'object' && !Array.isArray(r) && typeof r.text === 'string';
} Try / catch
try {
comments = normalizeCommentRows(rows, cmd);
} catch (e) {
const m = /malformed comment row at index (\d+)/.exec(e.message || '');
if (e instanceof CommandExecutionError && m) {
console.warn('Skipping bad row at index', m[1]);
rows.splice(Number(m[1]), 1);
comments = normalizeCommentRows(rows, cmd);
} else throw e;
} Prevention
- Pre-filter null/placeholder rows (deleted comments) before normalizing.
- Inspect the reported index to identify bad elements quickly.
- Keep extraction code skipping non-object entries.
- Validate with a schema (text string, likes number) before calling the API.
When it happens
Trigger: The comments array contains null, a string, a number, or a nested array at some position - usually sparse data or a changed payload where some entries are placeholders.
Common situations: Deleted/filtered comments serialized as null, XHS returning partial rows, or callers concatenating mixed data into the array.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- ${commandName}: malformed comment row ${field}
- ${commandName}: malformed comment row images
- ${commandName}: malformed comments payload
- Unexpected Xiaohongshu search harvest row ${index + 1} shape
- Unexpected Xiaohongshu search harvest row ${index + 1} shape
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a8d1a1bd9f9dbc72.
Report an issue: GitHub.