{"record":{"id":"eb8031fc3adaf4ac","repo":"jackwener/OpenCLI","slug":"flathub-label-cannot-be-empty","errorCode":null,"errorMessage":"flathub ${label} cannot be empty","messagePattern":"flathub (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/flathub/utils.js","lineNumber":19,"sourceCode":"// Shared helpers for the Flathub adapters (https://flathub.org).\n//\n// Flathub is the canonical Linux flatpak app registry. Public REST API at\n// `flathub.org/api/v2`, no auth, no key. Two endpoints we surface:\n//   • POST /search      → keyword search, returns app metadata\n//   • GET  /appstream/<appId> → full appstream metadata for one app\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const FLATHUB_API_BASE = 'https://flathub.org/api/v2';\nexport const FLATHUB_APP_BASE = 'https://flathub.org/apps';\nconst UA = 'opencli-flathub-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// AppStream IDs are reverse-DNS (e.g. \"org.gnome.Calculator\"); the spec allows\n// letters, digits, `.`, `_`, `-`. Min two segments separated by `.`.\nconst APP_ID_PATTERN = /^[A-Za-z][A-Za-z0-9_-]*(?:\\.[A-Za-z0-9_][A-Za-z0-9_-]*){1,}$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`flathub ${label} cannot be empty`);\n    return s;\n}\n\nexport function requireBoundedInt(value, defaultValue, maxValue, label = 'limit') {\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(`flathub ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`flathub ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requireAppId(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) throw new ArgumentError('flathub appId is required (e.g. \"org.mozilla.firefox\")');","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/flathub/utils.js#L1-L37","documentation":"requireString validates that a user-supplied string argument (labelled, e.g. 'query') is non-empty after trimming; otherwise it throws ArgumentError with 'flathub <label> cannot be empty'. The library throws this early to fail fast before making any network request with an unusable value.","triggerScenarios":"Calling an adapter that calls requireString(value, label) with null, undefined, '', whitespace-only, or a value coercing to '' (e.g. requireString(query) where query comes from an unset CLI flag or empty env var).","commonSituations":"CLI invoked with a missing positional argument; shell variable expansion producing an empty string ($QUERY unset); passing an empty object/string from a script; trailing-whitespace-only input.","solutions":["Supply a non-empty value for the argument (e.g. the search query)","Check the variable feeding the argument is actually set before calling","Trim and validate inputs in your script before invoking the adapter","If using CLI flags, pass the value explicitly rather than relying on defaults"],"exampleFix":"// before\nconst query = process.env.QUERY; // may be undefined\nawait searchApps(query);\n// after\nconst query = (process.env.QUERY ?? '').trim();\nif (!query) throw new Error('QUERY env var is required');\nawait searchApps(query);","handlingStrategy":"validation","validationCode":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}\nif (!isNonEmptyString(query)) throw new Error('query must be a non-empty string');","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await searchApps(query);\n} catch (err) {\n  if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {\n    console.error(`Missing required argument: ${err.message}`);\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Validate required CLI args before invoking adapters","Check env vars are set/exported before interpolation into arguments","Trim user input and reject whitespace-only values early","Use shell parameter expansion guards like ${VAR:?message} in scripts"],"tags":["argument-validation","input-error","empty-string"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}