{"id":"3cbe4d3f41e16c27","repo":"redis/node-redis","slug":"invalid-unix-url","errorCode":null,"errorMessage":"Invalid unix URL","messagePattern":"Invalid unix URL","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/client/lib/client/index.ts","lineNumber":541,"sourceCode":"      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    }\n\n    const [, username, password, rawPath, rawQuery] = match,\n      parsed: AnyRedisClientOptions & {\n        socket: Exclude<AnyRedisClientOptions['socket'], undefined> & {\n          tls: boolean\n        }\n      } = {\n        socket: {\n          path: decodeURIComponent(rawPath),\n          tls: false\n        }\n      };\n\n    if (username) {\n      parsed.username = decodeURIComponent(username);\n    }\n","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/redis/node-redis/blob/bb5beb56578573910e2ee8f39681edc214c41398/packages/client/lib/client/index.ts#L523-L559","documentation":"For unix:// URLs the client uses a regex (#parseUnixURL) because WHATWG URL cannot parse a unix authority. The regex requires a non-root socket path (the part after unix://[user[:pass]@]); if the match fails or the path is exactly '/', it throws 'Invalid unix URL'. A unix socket URL must therefore be of the form unix:///var/run/redis/redis-server.sock (optionally with credentials and a ?db=N query).","triggerScenarios":"`createClient({ url: 'unix://' })` (no path); `unix://localhost:6379` (treating it like a tcp URL); a malformed path missing the leading slash; a unix URL with credentials in an unsupported position.","commonSituations":"Confusing unix:// with redis:// (passing host:port to unix://); typo in the socket path; copy-pasting a Redis URI but keeping the unix:// scheme; building the URL dynamically and dropping the path component.","solutions":["Provide the full socket path: 'unix:///var/run/redis/redis-server.sock'.","If you meant a TCP connection, use 'redis://host:port' instead of 'unix://'.","Include credentials as unix://user:pass@/path/to/sock if needed."],"exampleFix":"// before\ncreateClient({ url: 'unix://localhost:6379' });\n\n// after\ncreateClient({ socket: { host: 'localhost', port: 6379 } });\n// or for an actual unix socket:\ncreateClient({ url: 'unix:///var/run/redis/redis-server.sock' });","handlingStrategy":"validation","validationCode":"function assertUnixUrl(url) {\n  if (!/^unix:\\/\\/(?:[^:@\\/]*(?::[^@\\/]*)?@)?\\/[^?#]+/.test(url)) {\n    throw new TypeError('Expected unix:///path/to/sock');\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the full socket path: unix:///var/run/redis/redis-server.sock.","For TCP, use redis://host:port, not unix://.","Build unix URLs from a validated socket path variable."],"tags":["config","url","unix-socket","validation"],"analyzedSha":"bb5beb56578573910e2ee8f39681edc214c41398","analyzedAt":"2026-08-03T19:09:15.686Z","schemaVersion":2}