{"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/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L506-L542","documentation":"In parseURL, if the URL pathname is longer than just '/', the client treats the segment after the slash as the database number (e.g. /3 => database 3). If Number(pathname) is NaN — e.g. '/abc' or '/1a' — it cannot SELECT a valid DB and throws 'Invalid pathname'. Only an integer DB index (or empty pathname) is accepted.","triggerScenarios":"`createClient({ url: 'redis://host:6379/abc' })`; `redis://host/mydb`; a URL with a trailing path component that is not an integer (e.g. a service path or tenant id mistakenly placed in the path).","commonSituations":"Putting a logical name/tenant in the URL path instead of a numeric DB; copy-paste from a multi-tenant URL scheme; a proxy that appends a path segment; confusion with HTTP-style path routing.","solutions":["Use an integer database index in the path: redis://host:6379/3, or omit it (defaults to 0).","If you need logical isolation, use the `keyPrefix` option or SELECT a DB via the `database` option instead of the path.","Move tenant/namespace info out of the URL path."],"exampleFix":"// before\ncreateClient({ url: 'redis://host:6379/tenantA' });\n\n// after\ncreateClient({ url: 'redis://host:6379/0', keyPrefix: 'tenantA:' });","handlingStrategy":"validation","validationCode":"function redisDbFromUrl(url) {\n  const u = new URL(url);\n  if (u.pathname.length > 1) {\n    const db = Number(u.pathname.slice(1));\n    if (!Number.isInteger(db) || db < 0) throw new TypeError('Invalid DB in URL path');\n    return db;\n  }\n  return 0;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Put only an integer DB index in the URL path (or omit it).","Use keyPrefix or the database option for logical isolation instead of a path name."],"tags":["config","url","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}