{"record":{"id":"46b2aedc7d520db5","repo":"jackwener/OpenCLI","slug":"nuget-label-cannot-be-empty","errorCode":null,"errorMessage":"nuget ${label} cannot be empty","messagePattern":"nuget (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/nuget/utils.js","lineNumber":20,"sourceCode":"//\n// NuGet exposes two complementary endpoints:\n//   • `azuresearch-usnc.nuget.org/query` — full-text package search (V3)\n//   • `api.nuget.org/v3/registration5-semver1/<id>/index.json` — package detail\n// No API key required. Anonymous traffic is generous; we set a polite UA.\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const NUGET_SEARCH_BASE = 'https://azuresearch-usnc.nuget.org';\nexport const NUGET_REGISTRATION_BASE = 'https://api.nuget.org/v3/registration5-semver1';\nconst UA = 'opencli-nuget-adapter/1.0 (+https://github.com/jackwener/opencli; mailto:opencli@example.com)';\n\n// NuGet ID grammar (NuGet docs §package-id): up to 100 chars, alnum + `.` + `_` + `-`,\n// must start with letter/digit. Case-insensitive; we lowercase for the registration URL\n// because NuGet's CDN is case-sensitive on the path.\nconst PACKAGE_ID_PATTERN = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,99})$/;\n\nexport function requireString(value, label) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError(`nuget ${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(`nuget ${label} must be a positive integer`);\n    }\n    if (n > maxValue) {\n        throw new ArgumentError(`nuget ${label} must be <= ${maxValue}`);\n    }\n    return n;\n}\n\nexport function requirePackageId(value) {\n    const raw = String(value ?? '').trim();\n    if (!raw) throw new ArgumentError('nuget package id is required (e.g. \"Newtonsoft.Json\")');","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/nuget/utils.js#L2-L38","documentation":"An ArgumentError thrown by requireString when a required string argument (identified by label, e.g. 'query' or 'package id') is empty or whitespace after trimming. It guards entry points like nuget search's query so downstream URL construction and validation never receive blank input.","triggerScenarios":"Calling a command that routes through requireString with an empty string, whitespace-only string, null, or undefined for the labeled argument — e.g. nugetSearch('') or nugetSearch(null) reaching the query handler.","commonSituations":"Shell invocation with a missing quoted argument (e.g. `cli nuget search` with no query); environment-driven input where a variable is unset; programmatic calls passing null/undefined; user-submitted form values that are blank after trim().","solutions":["Supply a non-empty value for the argument (e.g. pass the actual search query or package id).","If scripting, quote the argument so the shell doesn't drop it: `cli nuget search \"newtonsoft\"`.","Check the environment variable/config source feeding the value — ensure it is set.","Validate/trim user input before calling, and prompt again if blank.","In code, fall back to a sensible default or throw a clearer domain error before invoking the library."],"exampleFix":"// before\nconst q = process.env.SEARCH_QUERY; // may be undefined\nawait nugetSearch(q); // ArgumentError: nuget query cannot be empty\n// after\nconst q = (process.env.SEARCH_QUERY ?? '').trim();\nif (!q) {\n  console.error('SEARCH_QUERY is required');\n  process.exit(1);\n}\nawait nugetSearch(q);","handlingStrategy":"validation","validationCode":"function requireQuery(q) {\n  if (typeof q !== 'string' || !q.trim()) throw new Error('query must be a non-empty string');\n  return q.trim();\n}\n// call: nugetSearch(requireQuery(userInput))","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await nugetSearch(query);\n} catch (err) {\n  if (err.name === 'ArgumentError' && String(err.message).includes('cannot be empty')) {\n    console.error('Please provide a search query, e.g. cli nuget search \"newtonsoft\"');\n  } else throw err;\n}","preventionTips":["Quote arguments in shell scripts so they are never dropped.","Validate and trim user input before calling library functions.","Check that env/config values feeding arguments are set.","Provide CLI-level usage checks that fail with a helpful message before reaching the library."],"tags":["nuget","argument-validation","empty-input"],"backgroundTag":"missing-or-empty-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}