{"record":{"id":"5b0f1ae95f6da195","repo":"jackwener/OpenCLI","slug":"goproxy-module-path-is-required-e-g-github-com","errorCode":null,"errorMessage":"goproxy module path is required (e.g. \"github.com/gin-gonic/gin\", \"golang.org/x/net\")","messagePattern":"goproxy module path is required \\(e\\.g\\. \"github\\.com/gin-gonic/gin\", \"golang\\.org/x/net\"\\)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/goproxy/utils.js","lineNumber":22,"sourceCode":"// and serves the GOPROXY protocol (`@latest`, `@v/list`, `@v/<ver>.info|mod|zip`).\n// Spec: https://go.dev/ref/mod#goproxy-protocol\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\n\nexport const GOPROXY_BASE = 'https://proxy.golang.org';\nconst UA = 'opencli-goproxy-adapter (+https://github.com/jackwener/opencli)';\n\n// Module paths look like host/path/...; conservative shape: at least one slash,\n// host segment is alnum + dots, path segments are alnum + dashes/dots/underscores/slashes.\n// We enforce at most 200 chars and reject characters that would need URL-escaping.\nconst MODULE_PATH = /^[A-Za-z0-9][A-Za-z0-9._\\/-]{0,199}$/;\n\n// Go semver tags include \"v\" prefix; we accept the GOPROXY canonical form.\nconst VERSION_TAG = /^v[0-9]+(\\.[0-9]+)*([-+][A-Za-z0-9._-]+)?$/;\n\nexport function requireModulePath(value) {\n    const s = String(value ?? '').trim();\n    if (!s) {\n        throw new ArgumentError(\n            'goproxy module path is required (e.g. \"github.com/gin-gonic/gin\", \"golang.org/x/net\")',\n            'Use the canonical module path that appears in `go.mod`.',\n        );\n    }\n    if (!MODULE_PATH.test(s) || !s.includes('/')) {\n        throw new ArgumentError(\n            `goproxy module path \"${value}\" is not a recognised Go module path`,\n            'Module paths look like \"github.com/<org>/<repo>\" or \"golang.org/x/<name>\".',\n        );\n    }\n    return s;\n}\n\nexport function requireVersionTag(value) {\n    const s = String(value ?? '').trim();\n    if (!s) throw new ArgumentError('goproxy --version cannot be empty');\n    if (!VERSION_TAG.test(s)) {\n        throw new ArgumentError(","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/goproxy/utils.js#L4-L40","documentation":"This ArgumentError is thrown by requireModulePath in clis/goproxy/utils.js:22 when the value coerced to a string and trimmed is empty. The goproxy adapter refuses to build a proxy.golang.org URL without a module path, since every GOPROXY endpoint (e.g. /github.com/org/repo/@v/list) is keyed on it.","triggerScenarios":"Calling requireModulePath(undefined), requireModulePath(null), requireModulePath(''), requireModulePath('   '), or any value that String()/trim() collapses to empty — e.g. modulePath() called without a --module flag in the CLI.","commonSituations":"Forgetting the --module/--mod argument on the CLI command; a script passing an unset environment variable or empty config field; a wrapper function with a null default that propagates into modulePath().","solutions":["Pass the canonical module path exactly as it appears in go.mod, e.g. requireModulePath('github.com/gin-gonic/gin').","Check CLI flags: the module argument is required; run `goproxy --help` and supply the missing flag.","If the value comes from config/env, guard for empty string/undefined before calling modulePath()."],"exampleFix":"// before\nconst mods = await goproxyList(modulePath());\n// after\nconst mods = await goproxyList(modulePath('github.com/gin-gonic/gin'));","handlingStrategy":"validation","validationCode":"function isValidModulePath(v) {\n  const s = String(v ?? '').trim();\n  return s.length > 0 && /^[A-Za-z0-9][A-Za-z0-9._\\/-]{0,199}$/.test(s) && s.includes('/');\n}\nif (!isValidModulePath(input)) throw new Error('module path required');","typeGuard":"const isNonEmptyString = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try {\n  const mod = modulePath(input);\n} catch (err) {\n  if (err instanceof ArgumentError && /module path is required/.test(err.message)) {\n    console.error('Usage: pass the module path from go.mod, e.g. github.com/org/repo');\n  } else throw err;\n}","preventionTips":["Always pass the exact module directive value from go.mod.","Mark the --module CLI flag as required so arg parsers reject its absence.","Default empty env/config values to undefined (not '') so required-arg checks fire with a clear message."],"tags":["argument-error","input-validation","goproxy"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}