{"record":{"id":"b77cf4bbe074e557","repo":"jackwener/OpenCLI","slug":"medium-tag-value-is-not-valid","errorCode":null,"errorMessage":"medium tag \"${value}\" is not valid","messagePattern":"medium tag \"(.+?)\" is not valid","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/medium/tag.js","lineNumber":57,"sourceCode":"\nfunction isoDateFromRfc822(value) {\n    if (!value) return '';\n    const d = new Date(value);\n    if (Number.isNaN(d.getTime())) return '';\n    return d.toISOString().slice(0, 10);\n}\n\nfunction stripHtml(value) {\n    return decodeHtml(String(value ?? '').replace(/<[^>]+>/g, ' ').replace(/\\s+/g, ' ').trim());\n}\n\nfunction requireTag(value) {\n    const s = String(value ?? '').trim().toLowerCase();\n    if (!s) {\n        throw new ArgumentError('medium tag is required (e.g. \"programming\", \"javascript\")');\n    }\n    if (!TAG_PATTERN.test(s)) {\n        throw new ArgumentError(\n            `medium tag \"${value}\" is not valid`,\n            'Tags are lowercase alphanumeric, optionally hyphenated (e.g. \"machine-learning\").',\n        );\n    }\n    return s;\n}\n\nfunction requireBoundedInt(value, defaultValue, maxValue) {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError('medium limit must be a positive integer');\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`medium limit must be <= ${maxValue}`);\n    }\n    return n;\n}","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/medium/tag.js#L39-L75","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","solutions":["Convert the tag to a valid slug: lowercase, spaces to hyphens, strip invalid characters (e.g. 'Machine Learning' -> 'machine-learning').","Check the actual Medium tag slug by searching medium.com and use the slug portion of the /tag/<slug> URL.","If a variable supplies the value, echo it first and quote it in the shell to catch stray characters.","If you believe a legitimate tag is rejected, file a bug with the tag and TAG_PATTERN from clis/medium/tag.js."],"exampleFix":"// before\ncli({ site: 'medium', command: 'tag', args: ['Machine Learning'] });\n// after\ncli({ site: 'medium', command: 'tag', args: ['machine-learning'] });","handlingStrategy":"validation","validationCode":"const TAG_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;\nif (!TAG_PATTERN.test(String(tag ?? '').trim().toLowerCase())) {\n  throw new Error(`Tag \"${tag}\" must be lowercase alphanumeric, optionally hyphenated`);\n}","typeGuard":"function isValidMediumTag(v) {\n  return typeof v === 'string' && /^[a-z0-9]+(-[a-z0-9]+)*$/.test(v.trim());\n}","tryCatchPattern":"try {\n  await run(['medium', 'tag', slug]);\n} catch (e) {\n  if (e instanceof ArgumentError && /tag .* is not valid/.test(e.message)) {\n    console.error(`Fix the tag slug: ${slug} -> ${slugToSlug(slug)}`);\n  } else throw e;\n}","preventionTips":["Slugify tags before passing: lowercase, trim, spaces to hyphens, strip punctuation.","Copy the slug directly from the medium.com/tag/<slug> URL rather than typing it.","Sanitize shell variables and always quote interpolated values.","Keep a checked list of valid tag slugs for scripted workflows."],"tags":["cli","validation","argument-error","input-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}