jackwener/OpenCLI · error · ArgumentError

Invalid novel ID: ${id}

Error message

Invalid novel ID: ${id}

What it means

The pixiv novel CLI command validates its positional id argument with /^\d+$/ before making any network request. Anything other than a pure digit string (empty, alphanumeric, URL pasted, whitespace) raises ArgumentError with a usage hint, since the /ajax/novel/{id} path requires a numeric novel ID.

Source

Thrown at clis/pixiv/novel.js:81

    url: `https://www.pixiv.net/novel/show.php?id=${identity.novelId}`,
  };
}

cli({
  site: 'pixiv',
  name: 'novel',
  access: 'read',
  description: 'View Pixiv novel metadata (title, author, series, tags, stats)',
  domain: 'www.pixiv.net',
  strategy: Strategy.COOKIE,
  args: [
    { name: 'id', required: true, positional: true, help: 'Novel ID' },
  ],
  columns: ['novel_id', 'title', 'author', 'user_id', 'series_id', 'series_title', 'series_order', 'words', 'characters', 'bookmarks', 'likes', 'views', 'tags', 'created', 'url'],
  func: async (page, kwargs) => {
    const id = String(kwargs.id ?? '');
    if (!/^\d+$/.test(id)) {
      throw new ArgumentError(`Invalid novel ID: ${id}`, 'Example: opencli pixiv novel 10588915');
    }
    const body = await pixivFetch(page, `/ajax/novel/${id}`, {
      notFoundMsg: `Novel not found: ${id}`,
    });
    return [novelRowFromBody(body, id)];
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Extract the numeric part: `opencli pixiv novel 10588915` (digits only)
  2. If you have a full URL, take the id= query parameter or the trailing numeric segment and pass just that
  3. Verify you are using a novel ID, not a series or user ID
  4. In scripts, quote/trim the argument and check it is non-empty before invoking

Example fix

// before
opencli pixiv novel https://www.pixiv.net/novel/show.php?id=10588915
// after
opencli pixiv novel 10588915
Defensive patterns

Strategy: validation

Validate before calling

function extractPixivNovelId(input) {
  const m = String(input).match(/(\d+)/);
  const id = m ? m[1] : '';
  if (!/^\d+$/.test(id)) throw new Error(`Invalid novel ID: ${input}`);
  return id;
}

Type guard

function isPixivNovelId(v) {
  return typeof v === 'string' && /^\d+$/.test(v);
}

Try / catch

try {
  const rows = await run(['pixiv', 'novel', rawId]);
} catch (e) {
  if (e instanceof ArgumentError && e.message.startsWith('Invalid novel ID')) {
    console.error('Pass digits only, e.g. opencli pixiv novel 10588915');
  } else throw e;
}

Prevention

When it happens

Trigger: Running `opencli pixiv novel` with no argument, a URL like https://www.pixiv.net/novel/show.php?id=10588915, an ID containing spaces or letters, or a slug from another Pixiv content type (series, user).

Common situations: Users paste the full Pixiv novel URL instead of the numeric ID; shell quoting issues; copying a series ID or user ID by mistake; empty variable expansion in scripts.

Related errors


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