jackwener/OpenCLI · error · ArgumentError

dockerhub image "${input}" name must be 2-255 chars

Error message

dockerhub image "${input}" name must be 2-255 chars

What it means

After slug validation, parseImage enforces Docker Hub's repository-name length rule of 2-255 characters. This ArgumentError is thrown when the parsed name part is a single character or longer than 255 chars.

Source

Thrown at clis/dockerhub/utils.js:62

    const slash = raw.indexOf('/');
    let owner;
    let name;
    if (slash >= 0) {
        owner = raw.slice(0, slash);
        name = raw.slice(slash + 1);
    }
    else {
        owner = 'library';
        name = raw;
    }
    if (!SLUG.test(owner) || !SLUG.test(name)) {
        throw new ArgumentError(
            `dockerhub image "${input}" is not a valid repository slug`,
            'Use lowercase letters / digits / "._-", optionally prefixed with "<owner>/".',
        );
    }
    if (name.length < 2 || name.length > 255) {
        throw new ArgumentError(
            `dockerhub image "${input}" name must be 2-255 chars`,
        );
    }
    return { owner, name };
}

export async function hubFetch(url, label) {
    let resp;
    try {
        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });
    }
    catch (err) {
        throw new CommandExecutionError(
            `${label} request failed: ${err?.message ?? err}`,
            'Check that hub.docker.com is reachable from this network.',
        );
    }
    if (resp.status === 404) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use an image name of at least 2 characters
  2. Truncate or fix over-long generated names to <= 255 chars
  3. If targeting a 1-char repo, note Docker Hub itself disallows it, so use a valid repo

Example fix

// before
dockerhub info --image 'a'
// after
dockerhub info --image 'library/ab'
Defensive patterns

Strategy: validation

Validate before calling

const name = args.image.includes('/') ? args.image.split('/')[1] : args.image; if (name.length < 2 || name.length > 255) throw new Error('repo name must be 2-255 chars');

Type guard

function hasValidNameLength(s) { const name = s.includes('/') ? s.slice(s.indexOf('/')+1) : s; return name.length >= 2 && name.length <= 255; }

Try / catch

try { await info(args); } catch (e) { if (e instanceof ArgumentError && e.message.includes('2-255 chars')) { console.error('Repo name must be 2-255 characters'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Passing a single-character image name like --image a (becomes library/a, name length 1); passing an extremely long generated name over 255 chars.

Common situations: Short test names in scripts; programmatically generated slugs that exceed 255 chars; forgetting that bare single-letter names get 'library/' owner and still fail on the name part.

Related errors


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