{"record":{"id":"798414fc55ec0a46","repo":"hibiken/asynq","slug":"asynq-could-not-parse-redis-uri-w","errorCode":null,"errorMessage":"asynq: could not parse redis uri: %w","messagePattern":"asynq: could not parse redis uri: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"asynq.go","lineNumber":479,"sourceCode":"\t\tWriteTimeout: opt.WriteTimeout,\n\t\tTLSConfig:    opt.TLSConfig,\n\t})\n}\n\n// ParseRedisURI parses redis uri string and returns RedisConnOpt if uri is valid.\n// It returns a non-nil error if uri cannot be parsed.\n//\n// Three URI schemes are supported, which are redis:, rediss:, redis-socket:, and redis-sentinel:.\n// Supported formats are:\n//\n//\tredis://[:password@]host[:port][/dbnumber]\n//\trediss://[:password@]host[:port][/dbnumber]\n//\tredis-socket://[:password@]path[?db=dbnumber]\n//\tredis-sentinel://[:password@]host1[:port][,host2:[:port]][,hostN:[:port]][/dbnumber][?master=masterName]\nfunc ParseRedisURI(uri string) (RedisConnOpt, error) {\n\tu, err := url.Parse(uri)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"asynq: could not parse redis uri: %w\", err)\n\t}\n\tswitch u.Scheme {\n\tcase \"redis\", \"rediss\":\n\t\treturn parseRedisURI(u)\n\tcase \"redis-socket\":\n\t\treturn parseRedisSocketURI(u)\n\tcase \"redis-sentinel\":\n\t\treturn parseRedisSentinelURI(u)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"asynq: unsupported uri scheme: %q\", u.Scheme)\n\t}\n}\n\nfunc parseRedisURI(u *url.URL) (RedisConnOpt, error) {\n\tvar db int\n\tvar err error\n\tvar redisConnOpt RedisClientOpt\n","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/hibiken/asynq/blob/d135f1439bee74e989b7f9b41ecd542cc87f024a/asynq.go#L461-L497","documentation":"Returned by ParseRedisURI when the URI string does not match any of the supported redis/rediss/redis-socket/redis-sentinel formats (bad scheme, malformed host/port, or unparseable components). The wrapped error %w carries the underlying parse failure; the URI is rejected before any Redis connection option is produced.","triggerScenarios":"Passing a syntactically invalid URI (e.g. missing scheme, stray characters, invalid percent-encoding) to ParseRedisURI or via a redis:// URI when configuring the server with Config{Redis: parsedOpt}.","commonSituations":"Environment-variable-provided Redis URLs with unescaped special characters in the password (@, :, /); copy-pasted URIs with quotes or whitespace; building the URI by string concatenation without escaping.","solutions":["Fix the URI syntax; the wrapped error from net/url points at the exact problem","URL-escape credentials with url.UserPassword or net/url escaping before composing the URI","Trim quotes/whitespace from environment variables before passing the value"],"exampleFix":"// before\nopt, err := asynq.ParseRedisURI(\"redis://user:p@ss@localhost:6379\")\n// after\nopt, err := asynq.ParseRedisURI(\"redis://user:p%40ss@localhost:6379\")","handlingStrategy":"validation","validationCode":"func validateRedisURI(uri string) error {\n    if _, err := url.Parse(uri); err != nil {\n        return fmt.Errorf(\"invalid redis uri: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"opt, err := asynq.ParseRedisURI(uri)\nif err != nil {\n    var urlErr *url.Error\n    if errors.As(err, &urlErr) {\n        return fmt.Errorf(\"bad redis URI %q: %v\", uri, urlErr.Err)\n    }\n    return err\n}","preventionTips":["Store Redis URIs in env/config and trim quotes and whitespace on read","Escape password characters (@, :, /, %) with url.UserPassword when composing URIs","Validate the URI at config-load time, before the server starts"],"tags":["go","redis","uri-parsing","configuration"],"backgroundTag":"invalid-url","analyzedSha":"d135f1439bee74e989b7f9b41ecd542cc87f024a","analyzedAt":"2026-09-07T19:02:34.660Z","contentChangedAt":"2026-09-07T19:02:34.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}