{"record":{"id":"ef70a59ff64b0559","repo":"abhigyanpatwari/GitNexus","slug":"unknown-resource-uri-uri","errorCode":null,"errorMessage":"Unknown resource URI: ${uri}","messagePattern":"Unknown resource URI: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gitnexus/src/mcp/resources.ts","lineNumber":170,"sourceCode":"  const v = raw.trim().toLowerCase();\n  if (v === 'true' || v === '1') return true;\n  if (v === 'false' || v === '0') return false;\n  return undefined;\n}\n\n/**\n * Parse a GitNexus resource URI (repos, setup, per-repo, or per-group templates).\n * Used by `readResource` and tests (round-trip / dispatch coverage).\n */\nexport function parseResourceUri(uri: string): ParsedGitnexusResource {\n  if (uri === 'gitnexus://repos') return { kind: 'repos' };\n  if (uri === 'gitnexus://setup') return { kind: 'setup' };\n\n  let u: URL;\n  try {\n    u = new URL(uri);\n  } catch {\n    throw new Error(`Unknown resource URI: ${uri}`);\n  }\n\n  if (u.protocol !== 'gitnexus:') {\n    throw new Error(`Unknown resource URI: ${uri}`);\n  }\n\n  if (u.hostname === 'group') {\n    const segments = u.pathname\n      .replace(/^\\/+|\\/+$/g, '')\n      .split('/')\n      .filter(Boolean);\n    if (segments.length < 2) {\n      throw new Error(\n        `Invalid group resource URI (expected gitnexus://group/{name}/contracts or .../status): ${uri}`,\n      );\n    }\n    const tail = segments[segments.length - 1]!;\n    if (tail !== 'contracts' && tail !== 'status') {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/0d1aed942f0e8b5d3bac27519fff441aceea722d/gitnexus/src/mcp/resources.ts#L152-L188","documentation":"Thrown by parseResourceUri when the resource URI cannot be parsed by the URL constructor at all. This is the first gate of GitNexus MCP resource parsing: only the two exact flat URIs (gitnexus://repos, gitnexus://setup) bypass parsing; everything else must at least be a well-formed URL or the URI is declared unknown with the original string echoed back.","triggerScenarios":"Reading a resource with a string that is not a valid URL — e.g. 'frontend/context', 'gitnexus:/repo/frontend' is parseable but other typos aside, strings with spaces or control characters like 'gitnexus:// repo/x' or 'not a uri' fail new URL() and hit this branch.","commonSituations":"Clients build URIs by string concatenation with unescaped names (spaces in repo names), pass a repo name instead of a full URI, or template systems inject empty/malformed segments. Copying a URI from logs where it was already mangled.","solutions":["Send fully-formed URIs of the form gitnexus://repo/{name}/{resource} or gitnexus://group/{name}/contracts|status.","Percent-encode dynamic path segments (encodeURIComponent) before composing the URI.","If you only have a repo name, resolve it first via the gitnexus://repos listing, then build the URI."],"exampleFix":"// before\nconst uri = `gitnexus://repo/${repoName}/context`; // repoName = 'my repo'\n\n// after\nconst uri = `gitnexus://repo/${encodeURIComponent(repoName)}/context`;","handlingStrategy":"validation","validationCode":"function isParsableResourceUri(uri: string): boolean {\n  if (uri === 'gitnexus://repos' || uri === 'gitnexus://setup') return true;\n  try { new URL(uri); return true; } catch { return false; }\n}\nif (!isParsableResourceUri(uri)) throw new Error(`Not a valid resource URI: ${uri}`);","typeGuard":"const isWellFormedUri = (uri: unknown): uri is string =>\n  typeof uri === 'string' && (() => { try { new URL(uri); return true; } catch { return false; } })();","tryCatchPattern":"try {\n  return await client.readResource({ uri });\n} catch (e) {\n  if (e instanceof Error && /Unknown resource URI/.test(e.message)) {\n    return null; // drop malformed entries when replaying a saved list\n  }\n  throw e;\n}","preventionTips":["Compose URIs from encoded parts: `gitnexus://repo/${encodeURIComponent(name)}/context`.","Validate every URI with new URL(...) client-side before sending it to resources/read.","Never pass bare repo names or copied-from-log strings as resource URIs."],"tags":["mcp","resources","uri-validation","url-parsing"],"backgroundTag":"invalid-resource-uri","analyzedSha":"0d1aed942f0e8b5d3bac27519fff441aceea722d","analyzedAt":"2026-08-20T23:29:22.980Z","contentChangedAt":"2026-08-20T23:29:22.980Z","schemaVersion":2},"datasetVersion":"2026-09-08T20:17:18.057Z"}