{"record":{"id":"8a97aef251af9a84","repo":"abhigyanpatwari/GitNexus","slug":"unsupported-npm-registry-protocol","errorCode":null,"errorMessage":"Unsupported npm registry protocol","messagePattern":"Unsupported npm registry protocol","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/update-cache.ts","lineNumber":73,"sourceCode":"}\n\nlet registryMemo: { key: string; value: { identity: string; packageUrl: string } } | undefined;\n\nexport function normalizedUpdateRegistry(env: NodeJS.ProcessEnv = process.env): {\n  identity: string;\n  packageUrl: string;\n} {\n  const key = env.npm_config_registry ?? '';\n  if (registryMemo?.key === key) return registryMemo.value;\n  const value = buildUpdateRegistry(key);\n  registryMemo = { key, value };\n  return value;\n}\n\nfunction buildUpdateRegistry(rawRegistry: string): { identity: string; packageUrl: string } {\n  const parsed = new URL(rawRegistry || DEFAULT_UPDATE_REGISTRY);\n  if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {\n    throw new Error('Unsupported npm registry protocol');\n  }\n  if (parsed.search || parsed.hash) {\n    throw new Error('Registry URL cannot contain query or fragment');\n  }\n  parsed.username = '';\n  parsed.password = '';\n  parsed.pathname = parsed.pathname.replace(/\\/+$/, '') || '/';\n\n  const pathname = parsed.pathname === '/' ? '' : parsed.pathname;\n  const identity = `${parsed.protocol}//${parsed.host}${pathname}`;\n  // `/<pkg>/latest` is the small dist-tag document. The full packument at\n  // `/<pkg>` is multi-megabyte on this package and cannot fit the fetch cap.\n  const packagePath = `${pathname}/gitnexus/latest`.replace(/\\/{2,}/g, '/');\n  return { identity, packageUrl: `${parsed.protocol}//${parsed.host}${packagePath}` };\n}\n\nexport function updateCheckCachePath(env: NodeJS.ProcessEnv = process.env): string {\n  return path.join(env.GITNEXUS_HOME || getGlobalDir(), 'update-check.json');","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/core/update-cache.ts#L55-L91","documentation":"buildUpdateRegistry in update-cache.ts validates the configured npm registry URL and throws when its protocol is neither https: nor http:. The update checker only talks to HTTP(S) registries, and stripping to these schemes prevents file:, data:, or other scheme-based bypasses.","triggerScenarios":"Passing a registry string such as 'ftp://registry.example.com', 'file:///local/registry', or a malformed value with no parseable scheme to the registry configuration consumed by buildUpdateRegistry (default applies only when the raw string is empty).","commonSituations":"Typo'd npmrc-style registry config ('registry.example.com' with no scheme — URL parses it as a path, protocol becomes 'file:' in some environments or fails); copy-pasting a custom registry URL from a vendor doc that omits https://.","solutions":["Prefix the registry value with 'https://' (or 'http://' only for local testing)","Check the env/config source feeding the registry value (e.g. NPM_CONFIG_REGISTRY or CLI flag) for a missing scheme","Validate the URL with `new URL(v).protocol` before setting it"],"exampleFix":"// before\nbuildUpdateRegistry('registry.npmjs.org'); // throws: protocol is not https:/http:\n// after\nbuildUpdateRegistry('https://registry.npmjs.org');","handlingStrategy":"validation","validationCode":"function validRegistry(v){ try { const p = new URL(v || 'https://registry.npmjs.org'); return p.protocol==='https:'||p.protocol==='http:'; } catch { return false; } }","typeGuard":null,"tryCatchPattern":"try { cache = buildUpdateRegistry(registryRaw); } catch (e) { if (e.message === 'Unsupported npm registry protocol') { log(`Registry '${registryRaw}' must start with https://`); fallbackToDefaultRegistry(); } else throw e; }","preventionTips":["Always write registry config values with an explicit https:// scheme","Lint/validate registry env vars (NPM_CONFIG_REGISTRY etc.) at startup","Never paste scheme-less hosts from docs into registry settings"],"tags":["npm","registry","config","url"],"backgroundTag":"invalid-config-value","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-09-08T00:40:44.970Z","contentChangedAt":"2026-09-08T00:40:44.970Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}