{"id":"aceaf013dd018327","repo":"go-redis/redis","slug":"redis-invalid-s-duration-w","errorCode":null,"errorMessage":"redis: invalid %s duration: %w","messagePattern":"redis: invalid (.+?) duration: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"options.go","lineNumber":809,"sourceCode":"\t}\n\t// try plain number first\n\tif i, err := strconv.Atoi(s); err == nil {\n\t\tif i <= 0 {\n\t\t\t// disable timeouts\n\t\t\treturn -1\n\t\t}\n\t\treturn time.Duration(i) * time.Second\n\t}\n\tdur, err := time.ParseDuration(s)\n\tif err == nil {\n\t\tif dur <= 0 {\n\t\t\t// disable timeouts\n\t\t\treturn -1\n\t\t}\n\t\treturn dur\n\t}\n\tif o.err == nil {\n\t\to.err = fmt.Errorf(\"redis: invalid %s duration: %w\", name, err)\n\t}\n\treturn 0\n}\n\nfunc (o *queryOptions) bool(name string) bool {\n\tswitch s := o.string(name); s {\n\tcase \"true\", \"1\":\n\t\treturn true\n\tcase \"false\", \"0\", \"\":\n\t\treturn false\n\tdefault:\n\t\tif o.err == nil {\n\t\t\to.err = fmt.Errorf(\"redis: invalid %s boolean: expected true/false/1/0 or an empty string, got %q\", name, s)\n\t\t}\n\t\treturn false\n\t}\n}\n","sourceCodeStart":791,"sourceCodeEnd":827,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/options.go#L791-L827","documentation":"Recorded on the queryOptions error slot by queryOptions.duration when a value is neither a plain integer (seconds) nor a valid time.ParseDuration string. Duration fields accept e.g. 5s, 250ms, or a bare integer of seconds; anything else is wrapped with the underlying parse error via %w.","triggerScenarios":"A URL like ?dial_timeout=5sec, ?read_timeout=fast, or ?conn_max_idle_time=1day (not a valid Go duration unit). The first bad duration parameter is the one reported.","commonSituations":"Using non-Go duration units (sec/min/day), missing the unit suffix on a non-integer, or pasting a value from a different client's config format.","solutions":["Use a Go duration string (5s, 250ms, 1m) or a bare integer for seconds.","Use a value <= 0 to disable the field where supported.","Remove the parameter to fall back to the default."],"exampleFix":"// before\nopt, err := redis.ParseURL(\"redis://localhost:6379/?dial_timeout=5sec\")\n// after\nopt, err := redis.ParseURL(\"redis://localhost:6379/?dial_timeout=5s\")","handlingStrategy":"validation","validationCode":"func validDurationParam(s string) bool {\n    if _, err := strconv.Atoi(s); err == nil { return true }\n    _, err := time.ParseDuration(s); return err == nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Go duration units (s, ms, m) or a bare integer of seconds.","Avoid non-Go units like sec/min/day.","Centralise duration formatting in config helpers."],"tags":["config","url","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}