{"record":{"id":"05f3d8d63f899bee","repo":"jackwener/OpenCLI","slug":"label-cannot-be-empty-05f3d8","errorCode":null,"errorMessage":"${label} cannot be empty","messagePattern":"(.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/_shared/search-adapter.js","lineNumber":6,"sourceCode":"import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport function requireSearchQuery(value, label = 'keyword') {\n  const query = String(value ?? '').trim();\n  if (!query) {\n    throw new ArgumentError(`${label} cannot be empty`);\n  }\n  return query;\n}\n\nexport function requireBoundedInteger(value, defaultValue, min, max, label) {\n  const raw = value ?? defaultValue;\n  const parsed = typeof raw === 'number' ? raw : Number(raw);\n  if (!Number.isInteger(parsed)) {\n    throw new ArgumentError(`${label} must be an integer between ${min} and ${max}, got ${JSON.stringify(value)}`);\n  }\n  if (parsed < min || parsed > max) {\n    throw new ArgumentError(`${label} must be between ${min} and ${max}, got ${parsed}`);\n  }\n  return parsed;\n}\n\nexport function requireNonNegativeInteger(value, defaultValue, label) {\n  const raw = value ?? defaultValue;","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/_shared/search-adapter.js#L1-L24","documentation":"requireSearchQuery in the shared search adapter trims its input and throws ArgumentError '<label> cannot be empty' (default label 'keyword') when the result is empty. It is the search-specific equivalent of requireNonEmptyQuery used by keyword-driven search commands.","triggerScenarios":"Calling requireSearchQuery with '', whitespace, null or undefined — e.g. a keyword CLI option omitted or bound to an empty shell variable.","commonSituations":"Unset keyword variable in automation scripts; user pressing enter at an interactive prompt; empty field in a YAML/JSON config driving the search; tokenization stripping all characters from the input.","solutions":["Supply a non-empty keyword (trimmed) to the search command.","Fail fast in scripts when the keyword variable is empty before invoking the CLI.","Pass an explicit label when wrapping so error messages name the actual option (e.g. 'query' vs 'keyword')."],"exampleFix":"// before\nrequireSearchQuery(process.env.KEYWORD)  // KEYWORD unset -> ''\n// after\nconst kw = (process.env.KEYWORD ?? '').trim();\nif (!kw) throw new Error('KEYWORD env var is required');\nrequireSearchQuery(kw);","handlingStrategy":"validation","validationCode":"const kw = String(value ?? '').trim();\nif (!kw) throw new Error('keyword is required');","typeGuard":"const hasKeyword = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  const keyword = requireSearchQuery(raw);\n} catch (err) {\n  if (err.name === 'ArgumentError' && err.message.includes('cannot be empty')) {\n    console.error('Search keyword missing; supply a non-empty --keyword.');\n  }\n  throw err;\n}","preventionTips":["Default empty keywords to an explicit error instead of empty string in scripts.","Validate env vars/config fields before passing to search commands.","Pass a descriptive label so errors name the actual option."],"tags":["validation","empty-input","search","cli"],"backgroundTag":"empty-required-input","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}