{"record":{"id":"33e7436ea1c3807a","repo":"jackwener/OpenCLI","slug":"maven-label-cannot-be-empty","errorCode":null,"errorMessage":"maven ${label} cannot be empty","messagePattern":"maven (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/maven/utils.js","lineNumber":18,"sourceCode":"// Shared helpers for the Maven Central (search.maven.org) adapter.\n//\n// Hits the public, unauthenticated `search.maven.org/solrsearch/select` Solr\n// endpoint that powers the Maven Central search UI. No auth required for\n// read-only queries.\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const MAVEN_BASE = 'https://search.maven.org/solrsearch/select';\nexport const MAVEN_REPO_BASE = 'https://repo1.maven.org/maven2';\nconst UA = 'opencli-maven-adapter (+https://github.com/jackwener/opencli)';\n\n// Maven groupId / artifactId tokens — Java-package-ish (letters / digits /\n// `_-.`), 1-200 chars; reverse-DNS dots are allowed in groupId.\nconst COORD_TOKEN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`maven ${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(`maven ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`maven ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\n/**\n * Parse a Maven coordinate `groupId:artifactId[:version]` into segments.\n * groupId / artifactId are required; version is optional.","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/maven/utils.js#L1-L36","documentation":"`requireString` validates that a labeled argument (e.g. 'query') is a non-empty string after trimming; if the value is null, undefined, whitespace, or otherwise stringifies to empty, it throws ArgumentError with `maven ${label} cannot be empty`. The library throws it eagerly so requests are never sent with a blank required parameter.","triggerScenarios":"Calling an operation that requires a string argument without providing it, e.g. `query(undefined)`, `query('')`, `query('   ')`, or `query(null)`. For maven search this means calling search with args.query missing or blank.","commonSituations":"An upstream config field or CLI flag is unset so the value arrives as undefined; a form/template interpolation produced an empty string; code reads the wrong property name (e.g. args.term instead of args.query); whitespace-only input pasted from docs.","solutions":["Provide the required argument, e.g. call search with a non-empty query string","Check where the value originates (CLI flag, env var, config) and ensure it is populated before the call","Trim/default the value at the boundary if empty input is legitimate in your flow","Read the error's label to identify which argument was empty ('maven query cannot be empty' -> the query argument)"],"exampleFix":"// before\nconst docs = await mavenSearch({ query: args.q }); // args.q is undefined\n// after\nconst docs = await mavenSearch({ query: requireNonEmpty(args.q, 'jackson-databind') });","handlingStrategy":"validation","validationCode":"function requireQuery(q) {\n  const s = typeof q === 'string' ? q.trim() : '';\n  if (!s) throw new Error('query must be a non-empty string');\n  return s;\n}","typeGuard":"function isNonEmptyString(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  const docs = await mavenSearch({ query });\n} catch (err) {\n  if (err instanceof ArgumentError && /cannot be empty/.test(err.message)) {\n    console.error('Provide a --query value');\n    process.exitCode = 2;\n    return;\n  }\n  throw err;\n}","preventionTips":["Validate CLI/config inputs at the boundary before calling library functions","Never pass possibly-undefined values straight through from config or env","Trim user input and reject whitespace-only strings early","Use labels/flag defaults so required fields can't be silently empty"],"tags":["argument-error","maven","empty-string","input-validation"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}