{"record":{"id":"f096675c4ed64675","repo":"redis/node-redis","slug":"invalid-pathname","errorCode":null,"errorMessage":"Invalid pathname","messagePattern":"Invalid pathname","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":524,"sourceCode":"    if (password) {\n      parsed.password = decodeURIComponent(password);\n    }\n\n    if (username || password) {\n      parsed.credentialsProvider = {\n        type: 'async-credentials-provider',\n        credentials: async () => (\n          {\n            username: username ? decodeURIComponent(username) : undefined,\n            password: password ? decodeURIComponent(password) : undefined\n          })\n      };\n    }\n\n    if (pathname.length > 1) {\n      const database = Number(pathname.substring(1));\n      if (isNaN(database)) {\n        throw new TypeError('Invalid pathname');\n      }\n\n      parsed.database = database;\n    }\n\n    return parsed;\n  }\n\n  static #parseUnixURL(url: string): AnyRedisClientOptions & {\n    socket: Exclude<AnyRedisClientOptions['socket'], undefined> & {\n      tls: boolean\n    }\n  } {\n    // unix://[user[:password]@]/path/to/sock[?db=N]\n    const match = /^unix:\\/\\/(?:([^:@/]*)(?::([^@/]*))?@)?(\\/[^?#]*)(?:\\?([^#]*))?(?:#.*)?$/.exec(url);\n    if (!match || match[3] === '/') {\n      throw new TypeError('Invalid unix URL');\n    }","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/redis/node-redis/blob/90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58/packages/client/lib/client/index.ts#L506-L542","documentation":"For redis:// and rediss:// URLs the optional pathname after the leading slash is interpreted as the logical database index and must be numeric (e.g. redis://h:6379/0). A non-numeric pathname like /foo or /db/0 is rejected.","triggerScenarios":"Passing redis://host:6379/foo or redis://host:6379/some/path to createClient.","commonSituations":"Mistakenly appending a REST-style path; confusing a Redis URL with an HTTP one; copy-paste error.","solutions":["Drop the pathname entirely (defaults to db 0), or","Use a single integer in [0,15] (or whatever the server's databases config allows)."],"exampleFix":"// before\ncreateClient({ url: 'redis://host:6379/main' });\n\n// after\ncreateClient({ url: 'redis://host:6379/0' });","handlingStrategy":"validation","validationCode":"function assertRedisPathname(url) {\n  const u = new URL(url);\n  if (u.pathname.length > 1 && !/^\\/\\d+$/.test(u.pathname)) {\n    throw new TypeError(`Invalid Redis db pathname ${u.pathname}; expected /<integer>`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the pathname as a single integer db index, not a REST path.","Omit the pathname to default to db 0.","Validate the URL shape at config load."],"tags":["url","config","validation","database"],"backgroundTag":null,"analyzedSha":"90fd0652bc3f2a0a1b2f79fa9096b02a86b0ac58","analyzedAt":"2026-08-11T15:37:21.243Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}