jackwener/OpenCLI · error · ArgumentError

Invalid bookmark type: ${type}. Expected "illust" or "novel"

Error message

Invalid bookmark type: ${type}. Expected "illust" or "novel".

What it means

normalizeBookmarkType validates the bookmark work type argument for pixiv CLI bookmark commands. Anything other than the exact strings 'illust' or 'novel' (after String coercion and trimming) is rejected with an ArgumentError, since the Pixiv API only supports these two bookmark categories.

Source

Thrown at clis/pixiv/bookmark-utils.js:15

import { ArgumentError, CommandExecutionError } from '@jackwener/opencli/errors';
import {
  getCurrentPixivUser,
  normalizePixivNonNegativeInteger,
  normalizePixivPositiveInteger,
  pixivFetch,
  requirePixivId,
  requirePixivPayloadObject,
  requirePixivString,
} from './utils.js';

export function normalizeBookmarkType(value) {
  const type = String(value ?? 'illust').trim();
  if (type !== 'illust' && type !== 'novel') {
    throw new ArgumentError(`Invalid bookmark type: ${type}. Expected "illust" or "novel".`);
  }
  return type;
}

export function dateOnly(value) {
  if (value == null || value === '') return '';
  if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}(?:T|$)/.test(value)) {
    throw new CommandExecutionError('Pixiv bookmark item returned malformed creation date');
  }
  return value.split('T')[0];
}

export function tagsToString(tags) {
  if (tags == null) return '';
  const values = Array.isArray(tags) ? tags : (Array.isArray(tags?.tags) ? tags.tags : null);
  if (!values) {
    throw new CommandExecutionError('Pixiv item returned malformed tags payload');
  }

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Set the type to exactly 'illust' or 'novel' (lowercase)
  2. Remove surrounding whitespace or casing issues — the value is trimmed but is case-sensitive
  3. Omit the value entirely: null/undefined defaults to 'illust'

Example fix

// before
normalizeBookmarkType('Artwork')
// after
normalizeBookmarkType('illust')
Defensive patterns

Strategy: validation

Validate before calling

function isValidBookmarkType(v) { const t = String(v ?? 'illust').trim(); return t === 'illust' || t === 'novel'; }
if (!isValidBookmarkType(opts.type)) throw new Error(`--type must be "illust" or "novel", got: ${opts.type}`);

Type guard

function isBookmarkType(v) { return typeof v === 'string' && (v.trim() === 'illust' || v.trim() === 'novel'); }

Try / catch

try { const type = normalizeBookmarkType(input); /* ... */ } catch (err) { if (err instanceof ArgumentError) { console.error(`Bad --type: use "illust" or "novel"`); process.exitCode = 1; } else throw err; }

Prevention

When it happens

Trigger: Calling a bookmark command (e.g. bookmark list/download) with --type set to a misspelled or unsupported value such as 'artwork', 'image', 'Illust' (uppercase), 'novels', or any non-empty string that is not exactly 'illust' or 'novel'.

Common situations: Typos in CLI flags, users copying examples for other Pixiv wrappers that use 'artwork'/'novels', case sensitivity mistakes, passing a numeric or object value that coerces to an unexpected string.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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