jackwener/OpenCLI · error · ArgumentError

medium tag is required (e.g. "programming", "javascript")

Error message

medium tag is required (e.g. "programming", "javascript")

What it means

requireTag validates the tag argument for the medium tag command. An empty (missing/null/whitespace) tag throws this ArgumentError, which explicitly shows example tags. Medium commands require a tag to operate on.

Source

Thrown at clis/medium/tag.js:54

    }
    return out;
}

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}`);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Pass a tag, e.g. medium tag programming or medium tag javascript.
  2. Check that the shell variable holding the tag is set before invoking.
  3. Add a usage check in wrapper scripts before calling the command.
  4. Quote the argument if it may contain hyphens or spaces: "machine-learning".

Example fix

// before
TAG=""; opencli medium tag "$TAG"
// after
TAG="${TAG:-}"
if [ -z "$TAG" ]; then echo 'usage: medium tag <tag>'; exit 2; fi
opencli medium tag "$TAG"
Defensive patterns

Strategy: validation

Validate before calling

const tag = (value ?? '').trim().toLowerCase();
if (!tag) throw new TypeError('medium tag is required');

Type guard

function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try { await mediumTag(tag); } catch (e) { if (String(e.message).includes('tag is required')) { printUsage(); process.exitCode = 2; return; } throw e; }

Prevention

When it happens

Trigger: Running the medium tag command without the tag argument; passing an unset shell variable; passing '' or ' '.

Common situations: Forgetting the positional argument in scripts; environment variables that failed to expand; copying a command template without filling in the tag.

Related errors


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