{"id":"d3d417b44309e956","repo":"go-redis/redis","slug":"redis-empty-unix-socket-path","errorCode":null,"errorMessage":"redis: empty unix socket path","messagePattern":"redis: empty unix socket path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":741,"sourceCode":"\t// leaving the brackets on the host, which the caller's net.JoinHostPort\n\t// would wrap again and turn \"redis://[::1]\" into \"[[::1]]:6379\".\n\thost, port := u.Hostname(), u.Port()\n\tif host == \"\" {\n\t\thost = \"localhost\"\n\t}\n\tif port == \"\" {\n\t\tport = \"6379\"\n\t}\n\treturn host, port\n}\n\nfunc setupUnixConn(u *url.URL) (*Options, error) {\n\to := &Options{\n\t\tNetwork: \"unix\",\n\t}\n\n\tif strings.TrimSpace(u.Path) == \"\" { // path is required with unix connection\n\t\treturn nil, errors.New(\"redis: empty unix socket path\")\n\t}\n\to.Addr = u.Path\n\to.Username, o.Password = getUserPassword(u)\n\treturn setupConnParams(u, o)\n}\n\ntype queryOptions struct {\n\tq   url.Values\n\terr error\n}\n\nfunc (o *queryOptions) has(name string) bool {\n\treturn len(o.q[name]) > 0\n}\n\nfunc (o *queryOptions) string(name string) string {\n\tvs := o.q[name]\n\tif len(vs) == 0 {","sourceCodeStart":723,"sourceCodeEnd":759,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/options.go#L723-L759","documentation":"Returned by setupUnixConn (options.go:741) when ParseURL is given a 'unix://' URL whose path is empty or whitespace-only. The unix socket path is the URL path component (e.g. '/var/run/redis/redis.sock'); without it there is no socket to dial, so ParseURL fails fast rather than producing a useless Options.","triggerScenarios":"Calling redis.ParseURL with 'unix://' (no path) or 'unix://?db=0' — the u.Path is empty after TrimSpace, so setupUnixConn returns this error. Reached via ParseURL's scheme switch at options.go:676-677.","commonSituations":"Building the URL from parts and forgetting to append the socket path; a config template with a placeholder that wasn't filled; using 'unix://host' style (unix sockets don't take a host, they take a path); trailing-slash-only 'unix:///' that gets trimmed.","solutions":["Provide the socket path in the URL: 'unix:///var/run/redis/redis.sock?db=0' (note the three slashes: scheme:///<path>).","If constructing Options directly (not via ParseURL), set Options.Network='unix' and Options.Addr to the socket path instead.","Validate the path is non-empty before calling ParseURL; surface a clearer application-level error."],"exampleFix":"// before\nopt, err := redis.ParseURL(\"unix://\")\n// -> 'redis: empty unix socket path'\n\n// after\nopt, err := redis.ParseURL(\"unix:///var/run/redis/redis.sock?db=0\")\n// or build Options directly:\n// opt := &redis.Options{Network: \"unix\", Addr: \"/var/run/redis/redis.sock\"}","handlingStrategy":"validation","validationCode":"u, err := url.Parse(raw)\nif err != nil { return nil, err }\nif u.Scheme == \"unix\" && strings.TrimSpace(u.Path) == \"\" {\n    return nil, fmt.Errorf(\"redis: empty unix socket path (got %q)\", raw)\n}\nreturn redis.ParseURL(raw)","typeGuard":null,"tryCatchPattern":"opt, err := redis.ParseURL(raw)\nif err != nil && strings.Contains(err.Error(), \"empty unix socket path\") {\n    // build Options directly instead\n    opt = &redis.Options{Network: \"unix\", Addr: socketPath}\n    err = nil\n}","preventionTips":["Use the three-slash form: unix:///path/to/redis.sock.","Validate the path is non-empty before ParseURL.","Prefer building Options directly when the socket path comes from config."],"tags":["options","url","unix-socket","config","parseurl"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}