{"id":"d6e66868ab19c347","repo":"redis/node-redis","slug":"invalid-db-query-parameter","errorCode":null,"errorMessage":"Invalid db query parameter","messagePattern":"Invalid db query parameter","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":580,"sourceCode":"    }\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 (rawQuery) {\n      const db = new URLSearchParams(rawQuery).get('db');\n      if (db !== null) {\n        const database = Number(db);\n        if (isNaN(database)) {\n          throw new TypeError('Invalid db query parameter');\n        }\n        parsed.database = database;\n      }\n    }\n\n    return parsed;\n  }\n\n  readonly #options: RedisClientOptions<M, F, S, RESP, TYPE_MAPPING>;\n  #socket: RedisSocket;\n  readonly #queue: RedisCommandsQueue;\n  #selectedDB = 0;\n  #monitorCallback?: MonitorCallback<TYPE_MAPPING>;\n  private _self = this;\n  private _commandOptions?: CommandOptions<TYPE_MAPPING>;\n  // flag used to annotate that the client\n  // was in a watch transaction when\n  // a topology change occurred","sourceCodeStart":562,"sourceCodeEnd":598,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L562-L598","documentation":"Inside #parseUnixURL, the optional query string may carry a `db` parameter (e.g. unix:///path/to/sock?db=2). If db is present but not a valid number (Number(db) is NaN), the client throws 'Invalid db query parameter'. This is the unix-socket analog of the 'Invalid pathname' check for tcp URLs.","triggerScenarios":"`unix:///path/to/sock?db=abc`; `?db=primary`; a query string with a non-numeric db; copy-pasting a query string that includes other params and a malformed db.","commonSituations":"Passing a logical DB name in the query; typo in the db value; a service template that injects a non-numeric db.","solutions":["Use an integer for db: unix:///path/to/sock?db=2, or omit it (defaults to 0).","Prefer the `database` option on createClient for clarity instead of the query string.","Validate the db value at config-load time."],"exampleFix":"// before\ncreateClient({ url: 'unix:///var/run/redis/redis-server.sock?db=cache' });\n\n// after\ncreateClient({ url: 'unix:///var/run/redis/redis-server.sock?db=1' });","handlingStrategy":"validation","validationCode":"function redisDbFromUnixUrl(url) {\n  const q = new URL(url.startsWith('unix://') ? 'http://x' + url.slice('unix'.length) : url).searchParams;\n  const db = q.get('db');\n  if (db !== null && (!Number.isInteger(Number(db)) || Number(db) < 0)) {\n    throw new TypeError('Invalid db query parameter');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use an integer for the db query param, or omit it.","Prefer the `database` createClient option for clarity."],"tags":["config","url","unix-socket","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}