jackwener/OpenCLI · error · CommandExecutionError

${commandName}: malformed comment row images

Error message

${commandName}: malformed comment row images

What it means

normalizeCommentImages expects the images field of a comment row to be an array (possibly null). A non-array value is treated as a malformed row and throws CommandExecutionError.

Source

Thrown at clis/xiaohongshu/comments.js:80

    const unit = short[2].toLowerCase();
    const multiplier = unit === 'w' || unit === '万' ? 10000 : 1000;
    return Math.round(numeric * multiplier);
}

function normalizeOptionalString(value, field, commandName) {
    if (value == null)
        return '';
    if (typeof value !== 'string') {
        throw new CommandExecutionError(`${commandName}: malformed comment row ${field}`);
    }
    return value;
}

export function normalizeCommentImages(value, commandName) {
    if (value == null)
        return [];
    if (!Array.isArray(value)) {
        throw new CommandExecutionError(`${commandName}: malformed comment row images`);
    }
    const urls = [];
    for (const raw of value) {
        if (typeof raw !== 'string') {
            throw new CommandExecutionError(`${commandName}: malformed comment row image URL`);
        }
        const trimmed = raw.trim();
        let parsed;
        try {
            parsed = new URL(trimmed);
        }
        catch {
            throw new CommandExecutionError(`${commandName}: malformed comment row image URL`);
        }
        if ((parsed.protocol !== 'https:' && parsed.protocol !== 'http:') || parsed.username || parsed.password) {
            throw new CommandExecutionError(`${commandName}: malformed comment row image URL`);
        }
        const href = parsed.toString();

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the raw comment row to confirm the images field's actual type.
  2. Wrap a single string in an array before passing it (or add coercion in normalizeCommentImages).
  3. Pre-validate rows with a schema/type check before normalizing.
  4. Update the normalizer if XHS changed the images container shape.

Example fix

// before
normalizeCommentImages(row.images, cmd);
// after
const images = Array.isArray(row.images) ? row.images
  : typeof row.images === 'string' ? [row.images] : [];
normalizeCommentImages(images, cmd);
Defensive patterns

Strategy: type-guard

Validate before calling

if (row.images != null && !Array.isArray(row.images)) {
  row.images = typeof row.images === 'string' ? [row.images] : [];
}

Type guard

function isImageList(v) {
  return v == null || (Array.isArray(v) && v.every(x => typeof x === 'string'));
}

Try / catch

try {
  images = normalizeCommentImages(row.images, cmd);
} catch (e) {
  if (e instanceof CommandExecutionError && /images/.test(e.message)) {
    images = [];
  } else throw e;
}

Prevention

When it happens

Trigger: row.images is a string, object, or number rather than an array of URL strings.

Common situations: Upstream payload change where images became an object map, or caller hand-assembling rows and passing a single URL string instead of an 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.

Related errors


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