jackwener/OpenCLI · error · CommandExecutionError

Pixiv novel returned malformed ${label}

Error message

Pixiv novel returned malformed ${label}

What it means

optionalCount validates numeric fields from the Pixiv novel detail payload (e.g. bookmark/series counts). If a field is present but is not a non-negative safe integer (or is negative), the library assumes the API response shape changed or the page returned junk, and throws CommandExecutionError with the field's label. null/'' are treated as legitimately absent and return ''.

Source

Thrown at clis/pixiv/novel.js:9

import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
import { pixivFetch } from './utils.js';
import { dateOnly, tagsToString } from './bookmark-utils.js';

function optionalCount(value, label) {
  if (value == null || value === '') return '';
  if (!Number.isSafeInteger(value) || value < 0) {
    throw new CommandExecutionError(`Pixiv novel returned malformed ${label}`);
  }
  return value;
}

function requireNovelBody(body, id) {
  if (!body || Array.isArray(body) || typeof body !== 'object') {
    throw new CommandExecutionError(`Pixiv novel ${id} returned malformed detail payload`);
  }
  const novelId = String(body.id ?? '').trim();
  const title = String(body.title ?? '').trim();
  const userName = String(body.userName ?? '').trim();
  const userId = String(body.userId ?? '').trim();
  if (!/^\d+$/.test(novelId) || novelId !== id || !title || !userName || !/^\d+$/.test(userId)) {
    throw new CommandExecutionError(`Pixiv novel ${id} returned malformed detail payload`);
  }
  return { payload: body, identity: { novelId, title, userName, userId } };
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command after confirming you are logged in and the page loads normally (an error/login page often yields malformed payloads).
  2. Update this CLI library to the latest version in case Pixiv changed the response shape and a fix was released.
  3. Inspect the raw payload returned for the novel ID to confirm which count field is malformed; if Pixiv changed the field type, patch optionalCount normalization (e.g. Number(value)) upstream.
Defensive patterns

Strategy: try-catch

Validate before calling

function isValidCount(v) {
  return v == null || v === '' || (Number.isSafeInteger(v) && v >= 0);
}
if (!isValidCount(body.bookmarkCount)) console.warn('count field malformed — Pixiv payload shape may have changed');

Type guard

function isNonNegSafeInt(v) {
  return typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
}

Try / catch

try {
  const row = await cli.pixiv.novelView({ id });
} catch (e) {
  if (/malformed/.test(e.message)) {
    console.error('Pixiv returned an unexpected payload (schema change or error page). Check login state, retry, or update the library.');
  } else throw e;
}

Prevention

When it happens

Trigger: The Pixiv novel detail endpoint (fetched via pixivFetch) returns a payload where a count field is a string, float, boolean, or negative number instead of a non-negative integer — e.g. HTML/error page parsed into the body, or a Pixiv API shape change.

Common situations: Pixiv schema changes after site updates; scraping a page that returned a login/captcha/error page so count fields are garbage; JSON field type drift (number became string).

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/a6d9f62cff4fbabf. Report an issue: GitHub.