jackwener/OpenCLI · error · ArgumentError

douyin videos limit must be an integer between ${MIN_LIMIT}

Error message

douyin videos limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}

What it means

An ArgumentError thrown by normalizeVideosLimit when the --limit value for douyin videos is not an integer, or falls outside [MIN_LIMIT, MAX_LIMIT]. Note the special case: undefined/null/'' defaults to DEFAULT_LIMIT, but any other non-numeric or non-integer string (e.g. '10.5', 'abc') becomes NaN or a float and fails the integer check.

Source

Thrown at clis/douyin/videos.js:20

import { ArgumentError } from '@jackwener/opencli/errors';
import { browserFetch } from './_shared/browser-fetch.js';
const WORK_LIST_URL = 'https://creator.douyin.com/janus/douyin/creator/pc/work_list';
// The server caps how many works come back per request regardless of page_size,
// so collecting a large --limit takes several cursor hops.
const MAX_HOPS = 50;
const DEFAULT_LIMIT = 20;
const MIN_LIMIT = 1;
const MAX_LIMIT = MAX_HOPS * 50;
function isScheduledWork(work) {
    return (work.public_time ?? 0) > Date.now() / 1000;
}
function countEligibleWorks(items, status) {
    return status === 'scheduled' ? items.filter(isScheduledWork).length : items.length;
}
export function normalizeVideosLimit(raw) {
    const value = raw === undefined || raw === null || raw === '' ? DEFAULT_LIMIT : Number(raw);
    if (!Number.isInteger(value) || value < MIN_LIMIT || value > MAX_LIMIT) {
        throw new ArgumentError(`douyin videos limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}`);
    }
    return value;
}
function pageSizeForLimit(limit) {
    if (limit < 20)
        return 20;
    if (limit > 50)
        return 50;
    return limit;
}
function normalizeVideoStatus(status, publicTime) {
    if (typeof status === 'number')
        return status;
    if (!status)
        return publicTime && publicTime > Date.now() / 1000 ? 'scheduled' : 'published';
    if (status.is_delete)
        return 'deleted';
    if (status.is_prohibited)

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass an integer within the allowed range, e.g. `--limit 50`.
  2. Omit --limit entirely to use the default value.
  3. Coerce upstream: Math.round / parseInt before passing, and clamp into [MIN_LIMIT, MAX_LIMIT].
  4. Log the exact flag value if your wrapper builds args dynamically — an empty-ish or malformed value bypasses the default and fails validation.

Example fix

// before
await run(['douyin', 'videos', '--limit', String(opts.count ?? '')]);
// after
const limit = Math.max(1, Math.round(Number(opts.count) || 50));
await run(['douyin', 'videos', '--limit', String(limit)]);
Defensive patterns

Strategy: validation

Validate before calling

function coerceVideosLimit(v, { min, max, dflt }) {
  if (v === undefined || v === null || v === '') return dflt;
  const n = Number(v);
  if (!Number.isInteger(n) || n < min || n > max) throw new Error(`limit must be an integer in [${min}, ${max}]`);
  return n;
}

Type guard

function isValidLimit(v, min, max) {
  const n = Number(v);
  return Number.isInteger(n) && n >= min && n <= max;
}

Try / catch

try {
  await run('douyin videos', { limit });
} catch (e) {
  if (e.name === 'ArgumentError' && /limit must be an integer/.test(e.message)) {
    console.error('Pass an integer limit or omit --limit for the default');
    process.exitCode = 2;
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `douyin videos --limit 0`, a negative number, a decimal like 2.5, a non-numeric string, or a value above the maximum, where Number.isInteger(value) is false or the bounds check fails.

Common situations: Shell/config supplying 'all' or a comma-separated list instead of a number; locale-formatted numbers ('1,000'); float math upstream producing 19.999999; unit confusion (expecting pages instead of items).

Related errors


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