jackwener/OpenCLI · error · CommandExecutionError

Pixiv novel returned malformed series order

Error message

Pixiv novel returned malformed series order

What it means

novelRowFromBody requires seriesOrder (seriesNavData.order or b.seriesContentOrder), when present, to be a safe integer >= 1. Zero, negative numbers, floats, strings, or overflow-size values indicate corrupted series ordering data, so the CLI throws CommandExecutionError rather than emitting a bogus series_order column.

Source

Thrown at clis/pixiv/novel.js:46

export function novelRowFromBody(body, id) {
  const normalized = requireNovelBody(body, id);
  const b = normalized.payload;
  const identity = normalized.identity;
  if (b.seriesNavData != null && (Array.isArray(b.seriesNavData) || typeof b.seriesNavData !== 'object')) {
    throw new CommandExecutionError('Pixiv novel returned malformed series metadata');
  }
  const series = b.seriesNavData || {};
  const seriesId = b.seriesId ?? series.seriesId ?? '';
  const seriesTitle = b.seriesTitle ?? series.title ?? '';
  if (seriesId !== '' && !/^\d+$/.test(String(seriesId))) {
    throw new CommandExecutionError('Pixiv novel returned malformed series ID');
  }
  if (seriesTitle !== '' && typeof seriesTitle !== 'string') {
    throw new CommandExecutionError('Pixiv novel returned malformed series title');
  }
  const seriesOrder = series.order ?? b.seriesContentOrder ?? '';
  if (seriesOrder !== '' && (!Number.isSafeInteger(seriesOrder) || seriesOrder < 1)) {
    throw new CommandExecutionError('Pixiv novel returned malformed series order');
  }
  return {
    novel_id: identity.novelId,
    title: identity.title,
    author: identity.userName,
    user_id: identity.userId,
    series_id: seriesId === '' ? '' : String(seriesId),
    series_title: seriesTitle || '',
    series_order: seriesOrder,
    words: optionalCount(b.wordCount, 'word count'),
    characters: optionalCount(b.characterCount ?? b.textCount, 'character count'),
    bookmarks: optionalCount(b.bookmarkCount, 'bookmark count') || 0,
    likes: optionalCount(b.likeCount, 'like count') || 0,
    views: optionalCount(b.viewCount, 'view count') || 0,
    tags: tagsToString(b.tags),
    created: dateOnly(b.createDate),
    url: `https://www.pixiv.net/novel/show.php?id=${identity.novelId}`,
  };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Inspect the raw response to see the exact seriesOrder value and type
  2. If it is a numeric string, coerce with Number()/parseInt and re-validate before calling novelRowFromBody
  3. Update the CLI to a version tolerant of the current Pixiv ordering format
  4. Fix fixtures/callers to use 1-based safe integers for seriesContentOrder

Example fix

// before
body.seriesContentOrder = "3"; // string
// after
body.seriesContentOrder = Number.parseInt(body.seriesContentOrder, 10); // 3
Defensive patterns

Strategy: validation

Validate before calling

const ord = body?.seriesNavData?.order ?? body?.seriesContentOrder;
if (ord !== undefined && ord !== '' &&
    (!(Number.isSafeInteger(Number(ord)) || Number(ord) >= 1))) {
  throw new Error(`bad series order: ${ord}`);
}

Type guard

function isPositiveSafeInt(v) {
  return Number.isSafeInteger(v) && v >= 1;
}

Try / catch

try {
  const row = novelRowFromBody(body, id);
} catch (e) {
  if (e.message.includes('malformed series order')) {
    const n = Number.parseInt(body.seriesNavData?.order, 10);
    if (Number.isSafeInteger(n) && n >= 1) body.seriesContentOrder = n;
  } else throw e;
}

Prevention

When it happens

Trigger: series.order is 0, negative, a decimal, a numeric string like "3", or exceeds Number.MAX_SAFE_INTEGER; only checked when the value is not ''.

Common situations: API returns 0-based order for a legacy series; a mirror serializes order as a string; JavaScript precision loss on very large order values from a crafted payload; fixtures using index 0.

Understand the failure class

Related errors


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