fix(command): return error on ModuleLoadex with nil config (#3916)

Calling ModuleLoadex(nil) previously panicked in toArgs. Return a sticky
command error instead.
This commit is contained in:
sonnemusk authored and GitHub committed 2026-07-22 14:01:52 +03:00
1 parent ee2703fd5e
commit f745ff4409
2 files changed
+22

No files matched your search

+5
View File
@@ -798,6 +798,11 @@ func (c *ModuleLoadexConfig) toArgs() []interface{} {
// ModuleLoadex Redis `MODULE LOADEX path [CONFIG name value [CONFIG name value ...]] [ARGS args [args ...]]` command.
func (c cmdable) ModuleLoadex(ctx context.Context, conf *ModuleLoadexConfig) *StringCmd {
if conf == nil {
cmd := NewStringCmd(ctx)
cmd.SetErr(errors.New("redis: ModuleLoadex nil config"))
return cmd
}
cmd := NewStringCmd(ctx, conf.toArgs()...)
_ = c(ctx, cmd)
return cmd
+17
View File
@@ -0,0 +1,17 @@
package redis
import (
"context"
"testing"
)
func TestModuleLoadexNilConfig(t *testing.T) {
rdb := NewClient(&Options{Addr: "localhost:6379"})
cmd := rdb.ModuleLoadex(context.Background(), nil)
if cmd.Err() == nil {
t.Fatal("expected error for nil config")
}
if cmd.Err().Error() != "redis: ModuleLoadex nil config" {
t.Fatalf("got %v", cmd.Err())
}
}