{"record":{"id":"2013ae9aae53358c","repo":"jackwener/OpenCLI","slug":"tvmaze-label-cannot-be-empty","errorCode":null,"errorMessage":"tvmaze ${label} cannot be empty","messagePattern":"tvmaze (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/tvmaze/utils.js","lineNumber":12,"sourceCode":"// Shared helpers for the TVmaze adapters.\n//\n// TVmaze publishes a free, unauthenticated REST API at https://api.tvmaze.com.\n// Docs: https://www.tvmaze.com/api\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const TVMAZE_BASE = 'https://api.tvmaze.com';\nconst UA = 'opencli-tvmaze-adapter (+https://github.com/jackwener/opencli)';\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`tvmaze ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireShowId(value) {\n    const raw = value;\n    const n = typeof raw === 'number' ? raw : Number(String(raw ?? '').trim());\n    if (!Number.isInteger(n) || n <= 0) {\n        throw new ArgumentError(\n            'tvmaze show id is required and must be a positive integer',\n            'TVmaze show ids appear in the URL: https://www.tvmaze.com/shows/<id>/<slug>.',\n        );\n    }\n    return n;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\n    const raw = value ?? defaultValue;\n    const n = typeof raw === 'number' ? raw : Number(raw);","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/tvmaze/utils.js#L1-L30","documentation":"requireString is the TVmaze adapter's input sanitizer: it coerces the value to a string, trims it, and throws ArgumentError if the result is empty. The `label` argument identifies which parameter failed (here invoked for `query`). It guarantees downstream URL building (e.g., encodeURIComponent(query)) never operates on an empty string.","triggerScenarios":"Calling a TVmaze command (e.g. `query`/search) with an empty, whitespace-only, null, or undefined query argument — e.g. `tvmaze search ''` or a script passing an unset shell variable.","commonSituations":"Unset environment variables interpolated into the command (`q=\"$MY_QUERY\"` with MY_QUERY empty); a config file with a blank field; piping empty stdin; forgetting to pass the positional argument so it defaults to undefined.","solutions":["Pass a non-empty query string to the command.","If the value comes from a variable or env var, echo it before the call to confirm it is populated.","Add a default or prompt in the calling script when the input is blank.","Catch ArgumentError in wrapper scripts and show a usage message."],"exampleFix":"// before\nconst query = process.env.SHOW_QUERY;\nawait tvmazeSearch(query); // SHOW_QUERY unset -> ArgumentError\n// after\nconst query = process.env.SHOW_QUERY;\nif (!query || !query.trim()) throw new Error('SHOW_QUERY env var must be set to a show name');\nawait tvmazeSearch(query);","handlingStrategy":"validation","validationCode":"function requireQuery(v) {\n    const s = String(v ?? '').trim();\n    if (!s) throw new Error('query must be a non-empty string');\n    return s;\n}","typeGuard":"function isNonEmptyString(v) {\n    return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n    const rows = await tvmazeSearch(rawQuery);\n} catch (err) {\n    if (err instanceof ArgumentError && err.message.includes('cannot be empty')) {\n        console.error('Usage: tvmaze search <query> — query must not be empty');\n        process.exitCode = 2;\n    } else {\n        throw err;\n    }\n}","preventionTips":["Check that env vars/variables feeding the query are set before invoking commands","Trim inputs and reject whitespace-only strings early in your script","Use shell parameter expansion defaults (${VAR:?message}) for required inputs","Show usage/help when a required positional argument is absent"],"tags":["validation","argument-error","input","tvmaze"],"backgroundTag":"missing-or-empty-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}