{"record":{"id":"dbcc9315f352bfb9","repo":"redis/go-redis","slug":"redis-moduleloadex-nil-config","errorCode":null,"errorMessage":"redis: ModuleLoadex nil config","messagePattern":"redis: ModuleLoadex nil config","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands.go","lineNumber":895,"sourceCode":"func (c *ModuleLoadexConfig) toArgs() []interface{} {\n\targs := make([]interface{}, 3, 3+len(c.Conf)*3+len(c.Args)*2)\n\targs[0] = \"MODULE\"\n\targs[1] = \"LOADEX\"\n\targs[2] = c.Path\n\tfor k, v := range c.Conf {\n\t\targs = append(args, \"CONFIG\", k, v)\n\t}\n\tfor _, arg := range c.Args {\n\t\targs = append(args, \"ARGS\", arg)\n\t}\n\treturn args\n}\n\n// ModuleLoadex Redis `MODULE LOADEX path [CONFIG name value [CONFIG name value ...]] [ARGS args [args ...]]` command.\nfunc (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd {\n\tif conf == nil {\n\t\tcmd := NewStringCmd(ctx)\n\t\tcmd.SetErr(errors.New(\"redis: ModuleLoadex nil config\"))\n\t\treturn cmd\n\t}\n\tcmd := NewStringCmd(ctx, conf.toArgs()...)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\n/*\nMonitor - represents a Redis MONITOR command, allowing the user to capture\nand process all commands sent to a Redis server. This mimics the behavior of\nMONITOR in the redis-cli.\n\nNotes:\n- Using MONITOR blocks the connection to the server for itself. It needs a dedicated connection\n- The user should create a channel of type string\n- This runs concurrently in the background. Trigger via the Start and Stop functions\nSee further: Redis MONITOR command: https://redis.io/commands/monitor\n*/","sourceCodeStart":877,"sourceCodeEnd":913,"githubUrl":"https://github.com/redis/go-redis/blob/c5cad058c72f58370553b48566302303cf8a2e89/commands.go#L877-L913","documentation":"Error produced by ModuleLoadex (commands.go:895) when the *ModuleLoadexConfig argument is nil. Instead of panicking on a nil dereference while building the MODULE LOADEX arguments, the method short-circuits and returns a StringCmd with this error set. Fix: pass a valid &ModuleLoadexConfig{Path: ...} with at least the module Path populated.","triggerScenarios":"Calling rdb.ModuleLoadex(ctx, nil).","commonSituations":"Passing a config variable that was declared but never initialized (var conf *ModuleLoadexConfig); a factory returning nil on failure whose result is passed straight through.","solutions":["Construct a config: &redis.ModuleLoadexConfig{Path: \"/path/to/module.so\", ...}.","Nil-check the config before calling.","Ensure any config-producing function returns a valid pointer or is handled on error."],"exampleFix":"// before\nvar conf *redis.ModuleLoadexConfig\nrdb.ModuleLoadex(ctx, conf)\n// after\nconf := &redis.ModuleLoadexConfig{Path: \"/usr/lib/redis/modules/module.so\"}\nrdb.ModuleLoadex(ctx, conf)","handlingStrategy":"validation","validationCode":"if conf == nil {\n    return errors.New(\"ModuleLoadexConfig must be provided\")\n}\nrdb.ModuleLoadex(ctx, conf)","typeGuard":"func validLoadex(conf *redis.ModuleLoadexConfig) bool {\n    return conf != nil && conf.Path != \"\"\n}","tryCatchPattern":null,"preventionTips":["Always construct the config with a composite literal, never var conf *T.","Nil-check factory results before passing them to ModuleLoadex."],"tags":["module-loadex","nil-pointer","validation"],"backgroundTag":"nil-argument","analyzedSha":"c5cad058c72f58370553b48566302303cf8a2e89","analyzedAt":"2026-09-01T06:50:53.388Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}