jackwener/OpenCLI · error · ArgumentError

dockerhub ${label} must be a positive integer

Error message

dockerhub ${label} must be a positive integer

What it means

requireBoundedInt validates that a labeled numeric argument is a positive integer within a max bound. This ArgumentError is thrown when the value is not an integer or is <= 0 (default label 'limit'). Docker Hub page_size requires a positive integer.

Source

Thrown at clis/dockerhub/utils.js:26

export const HUB_BASE = 'https://hub.docker.com/v2';
const UA = 'opencli-dockerhub-adapter (+https://github.com/jackwener/opencli)';

// Docker Hub repository slugs are 2-255 chars, lowercase alphanumerics + `_.-`,
// optionally prefixed with a Docker Hub user/org of the same charset.
const SLUG = /^[a-z0-9][a-z0-9._-]*$/;

export function requireString(value, label) {
    const s = String(value ?? '').trim();
    if (!s) throw new ArgumentError(`dockerhub ${label} cannot be empty`);
    return s;
}

export function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {
    const raw = value ?? defaultValue;
    const n = typeof raw === 'number' ? raw : Number(raw);
    if (!Number.isInteger(n) || n <= 0) {
        throw new ArgumentError(`dockerhub ${label} must be a positive integer`);
    }
    if (n > maxValue) {
        throw new ArgumentError(`dockerhub ${label} must be <= ${maxValue}`);
    }
    return n;
}

/**
 * Split an image identifier into `{owner, name}`. Bare names use the implicit
 * `library` owner that Docker Hub uses for official images (`nginx` →
 * `library/nginx`).
 */
export function parseImage(input) {
    const raw = String(input ?? '').trim().toLowerCase();
    if (!raw) {
        throw new ArgumentError('dockerhub image name is required (e.g. "nginx", "library/nginx", "bitnami/redis")');
    }
    const slash = raw.indexOf('/');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a positive integer, e.g. --limit 25
  2. Keep the value <= the command's max (100 for search)
  3. Fix the config/script value producing a non-numeric limit
  4. Omit the flag to use the default (25)

Example fix

// before
dockerhub search --query nginx --limit 0
// after
dockerhub search --query nginx --limit 25
Defensive patterns

Strategy: validation

Validate before calling

const n = Number(args.limit ?? 25); if (!Number.isInteger(n) || n <= 0) throw new Error(`--limit must be a positive integer, got ${args.limit}`);

Type guard

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

Try / catch

try { await search(args); } catch (e) { if (e instanceof ArgumentError && /must be a positive integer/.test(e.message)) { args.limit = 25; /* retry with default */ } else throw e; }

Prevention

When it happens

Trigger: Passing --limit 0, a negative number, a non-numeric string like 'all', a float like 2.5, or a value that Number() coerces to NaN/Infinity.

Common situations: Setting limit from a config file where it's an empty string; typos like '--limit 2five'; users expecting limit=0 to mean 'unlimited'.

Related errors


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