jackwener/OpenCLI · error · ArgumentError

medium tag "${value}" is not valid

Error message

medium tag "${value}" is not valid

What it means

The medium CLI tag command validates tag slugs with TAG_PATTERN before issuing an RSS request. requireTag normalizes the value (trims, lowercases) and throws ArgumentError when the result contains characters outside lowercase alphanumeric/hyphen. This fails fast so the network request is never made with a malformed tag.

Source

Thrown at clis/medium/tag.js:57

function isoDateFromRfc822(value) {
    if (!value) return '';
    const d = new Date(value);
    if (Number.isNaN(d.getTime())) return '';
    return d.toISOString().slice(0, 10);
}

function stripHtml(value) {
    return decodeHtml(String(value ?? '').replace(/<[^>]+>/g, ' ').replace(/\s+/g, ' ').trim());
}

function requireTag(value) {
    const s = String(value ?? '').trim().toLowerCase();
    if (!s) {
        throw new ArgumentError('medium tag is required (e.g. "programming", "javascript")');
    }
    if (!TAG_PATTERN.test(s)) {
        throw new ArgumentError(
            `medium tag "${value}" is not valid`,
            'Tags are lowercase alphanumeric, optionally hyphenated (e.g. "machine-learning").',
        );
    }
    return s;
}

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

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Convert the tag to a valid slug: lowercase, spaces to hyphens, strip invalid characters (e.g. 'Machine Learning' -> 'machine-learning').
  2. Check the actual Medium tag slug by searching medium.com and use the slug portion of the /tag/<slug> URL.
  3. If a variable supplies the value, echo it first and quote it in the shell to catch stray characters.
  4. If you believe a legitimate tag is rejected, file a bug with the tag and TAG_PATTERN from clis/medium/tag.js.

Example fix

// before
cli({ site: 'medium', command: 'tag', args: ['Machine Learning'] });
// after
cli({ site: 'medium', command: 'tag', args: ['machine-learning'] });
Defensive patterns

Strategy: validation

Validate before calling

const TAG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
if (!TAG_PATTERN.test(String(tag ?? '').trim().toLowerCase())) {
  throw new Error(`Tag "${tag}" must be lowercase alphanumeric, optionally hyphenated`);
}

Type guard

function isValidMediumTag(v) {
  return typeof v === 'string' && /^[a-z0-9]+(-[a-z0-9]+)*$/.test(v.trim());
}

Try / catch

try {
  await run(['medium', 'tag', slug]);
} catch (e) {
  if (e instanceof ArgumentError && /tag .* is not valid/.test(e.message)) {
    console.error(`Fix the tag slug: ${slug} -> ${slugToSlug(slug)}`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `medium tag` (or the underlying requireTag) with a tag containing uppercase letters, spaces, underscores, dots, or other symbols not accepted by TAG_PATTERN, e.g. `medium tag 'Machine Learning'` or `medium tag node_js`.

Common situations: Users typing tags with natural-language phrasing or camelCase; copying tag names like 'machine_learning' from other platforms; passing an empty or whitespace-only value (that path throws the sibling 'tag is required' error instead); scripting with unquoted shell variables containing spaces.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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