{"record":{"id":"9e559520b3a98f43","repo":"jackwener/OpenCLI","slug":"name-is-required-9e5595","errorCode":null,"errorMessage":"--${name} is required","messagePattern":"--(.+?) is required","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/wttr/utils.js","lineNumber":13,"sourceCode":"// wttr.in shared helpers — global weather (no auth, terminal-friendly JSON via ?format=j1).\n//\n// Coverage: worldwide. Unlike NWS (US-only), wttr.in geocodes any city/airport\n// code/lat,lon string and serves a 3-day forecast + current conditions in one\n// payload.\nimport { ArgumentError, EmptyResultError, CommandExecutionError } from '@jackwener/opencli/errors';\n\nexport const WTTR_BASE = 'https://wttr.in';\nconst UA = 'opencli-wttr/1.0';\n\nexport function requireString(value, name) {\n    if (typeof value !== 'string' || !value.trim()) {\n        throw new ArgumentError(`--${name} is required`);\n    }\n    return value.trim();\n}\n\nexport async function wttrFetch(location, label) {\n    // wttr.in path-encodes the location. Spaces → %20 is fine; commas survive.\n    const url = `${WTTR_BASE}/${encodeURIComponent(location)}?format=j1`;\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'User-Agent': UA, accept: 'application/json' } });\n    } catch (err) {\n        throw new CommandExecutionError(`${label} request failed: ${err.message}`);\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `${label} could not find location \"${location}\".`);\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}.`);","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/wttr/utils.js#L1-L31","documentation":"This ArgumentError from requireString is thrown when a required CLI argument is missing, not a string, or an empty/whitespace-only string. It fails fast before any network call, and the message names the flag (prefixed with --) that must be supplied.","triggerScenarios":"Calling query (or any requireString caller) without args.location, with location: undefined/null, or with location: '' or '   '.","commonSituations":"Forgetting the --location flag on the command line; a script variable that is undefined because an env var was unset; empty string after shell quoting mistakes.","solutions":["Pass a non-empty location, e.g. --location 'New York'","Check that the variable feeding the argument is defined and non-blank","Trim or validate user input before passing it"],"exampleFix":"// before\nawait query({ location: process.env.CITY }); // CITY unset -> undefined\n// after\nconst city = process.env.CITY?.trim();\nif (!city) throw new Error('Set CITY env var');\nawait query({ location: city });","handlingStrategy":"validation","validationCode":"function requireString(value, name) {\n  if (typeof value !== 'string' || !value.trim()) {\n    throw new Error(`--${name} is required`);\n  }\n  return value.trim();\n}\nconst location = requireString(args.location, 'location');","typeGuard":"function isNonEmptyString(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  result = await query({ location: args.location });\n} catch (err) {\n  if (err instanceof ArgumentError && err.message.includes('is required')) {\n    console.error('Usage: --location <city|lat,lon>');\n  } else throw err;\n}","preventionTips":["Always validate required CLI args at entry point before calling the library","Coerce and trim shell/env input; check for undefined and empty strings","Provide sensible defaults or interactive prompts for missing flags"],"tags":["argument-validation","cli","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}