{"record":{"id":"4d8d7fe26d9f87a4","repo":"redis/go-redis","slug":"at-least-one-of-libname-and-libver-should-be-set","errorCode":null,"errorMessage":"at least one of LibName and LibVer should be set","messagePattern":"at least one of LibName and LibVer should be set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands.go","lineNumber":354,"sourceCode":"\tvar cmd *StatusCmd\n\tif info.LibName != nil {\n\t\tlibName := fmt.Sprintf(\"go-redis(%s,%s)\", *info.LibName, internal.ReplaceSpaces(runtime.Version()))\n\t\tcmd = NewStatusCmd(ctx, \"client\", \"setinfo\", \"LIB-NAME\", libName)\n\t} else {\n\t\tcmd = NewStatusCmd(ctx, \"client\", \"setinfo\", \"LIB-VER\", *info.LibVer)\n\t}\n\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\n// Validate checks if only one field in the struct is non-nil.\nfunc (info LibraryInfo) Validate() error {\n\tif info.LibName != nil && info.LibVer != nil {\n\t\treturn errors.New(\"both LibName and LibVer cannot be set at the same time\")\n\t}\n\tif info.LibName == nil && info.LibVer == nil {\n\t\treturn errors.New(\"at least one of LibName and LibVer should be set\")\n\t}\n\treturn nil\n}\n\n// Hello sets the resp protocol used.\nfunc (c statefulCmdable) Hello(ctx context.Context,\n\tver int, username, password, clientName string,\n) *MapStringInterfaceCmd {\n\targs := make([]interface{}, 0, 7)\n\targs = append(args, \"hello\", ver)\n\tif password != \"\" {\n\t\tif username != \"\" {\n\t\t\targs = append(args, \"auth\", username, password)\n\t\t} else {\n\t\t\targs = append(args, \"auth\", \"default\", password)\n\t\t}\n\t}\n\tif clientName != \"\" {","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/commands.go#L336-L372","documentation":"Error returned by LibraryInfo.Validate (commands.go:354) when neither LibName nor LibVer is set in the LibraryInfo struct passed to CLIENT SETINFO. The Redis CLIENT SETINFO command requires at least one of LIB-NAME or LIB-VER to be provided, so the client rejects a fully empty LibraryInfo before sending anything to the server. Fix: set LibName, LibVer, or both — but not simultaneously, since setting both triggers a separate mutual-exclusion error.","triggerScenarios":"Calling ClientSetInfo with redis.LibraryInfo{} (both pointer fields nil).","commonSituations":"Building LibraryInfo dynamically from variables that may be unset and forgetting to check; copying an options struct where both fields were never populated.","solutions":["Populate at least one field, e.g. LibName: redis.StringPtr(\"myapp\").","Guard the call: only invoke ClientSetInfo when the LibraryInfo value validates.","Skip the call entirely if you have nothing to report to the server."],"exampleFix":"// before\ninfo := redis.LibraryInfo{}\nrdb.ClientSetInfo(ctx, info)\n// after\nif info.LibName != nil || info.LibVer != nil {\n    rdb.ClientSetInfo(ctx, info)\n}","handlingStrategy":"validation","validationCode":"func hasAnyField(info redis.LibraryInfo) bool {\n    return info.LibName != nil || info.LibVer != nil\n}\nif !hasAnyField(info) { return errors.New(\"LibraryInfo is empty\") }","typeGuard":"func nonEmpty(info redis.LibraryInfo) bool {\n    return info.LibName != nil || info.LibVer != nil\n}","tryCatchPattern":null,"preventionTips":["Never construct redis.LibraryInfo{} literally without fields.","Default to LibName: redis.StringPtr(<app name>) in shared helpers.","Skip the ClientSetInfo call when there is nothing to report."],"tags":["client-setinfo","validation","configuration"],"backgroundTag":"client-setinfo-validation","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}