Skip to content

Commit fa8f4fc

Browse files
authored
fix: handle nil options in TFunctionLoadArgs (#936)
## Summary - Fix potential panic in `TFunctionLoadArgs` when `nil` options are passed - Add nil check that delegates to `TFunctionLoad` when options is nil - Add test case for nil options scenario ## Motivation There was a `FIXME` comment indicating that nil options check was needed: ```go // FIXME: should check nil of options func (c *Compat) TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd { // ... if options.Replace { // <- panic if options is nil When nil is passed as options, accessing options.Replace causes a panic. ``` ## Changes This PR follows the same pattern used in other functions like HGetEXWithArgs and HSetEXWithArgs: ``` func (c *Compat) TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd { if options == nil { return c.TFunctionLoad(ctx, lib) } // ... } ```
1 parent 19aaff8 commit fa8f4fc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

rueidiscompat/adapter.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3483,8 +3483,10 @@ func (c *Compat) TFunctionLoad(ctx context.Context, lib string) *StatusCmd {
34833483
return newStatusCmd(resp)
34843484
}
34853485

3486-
// FIXME: should check nil of options
34873486
func (c *Compat) TFunctionLoadArgs(ctx context.Context, lib string, options *TFunctionLoadOptions) *StatusCmd {
3487+
if options == nil {
3488+
return c.TFunctionLoad(ctx, lib)
3489+
}
34883490
b := c.client.B()
34893491
var cmd cmds.Completed
34903492
if options.Replace {

rueidiscompat/adapter_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9498,6 +9498,7 @@ func testAdapterCache(resp3 bool) {
94989498
Expect(adapter.FlushDB(ctx).Err()).NotTo(HaveOccurred())
94999499
adapter.TFunctionDelete(ctx, "lib1")
95009500
adapter.TFunctionDelete(ctx, "lib2")
9501+
adapter.TFunctionDelete(ctx, "lib3")
95019502
})
95029503
// Copied from go-redis
95039504
// https://github.com/redis/go-redis/blob/f994ff1cd96299a5c8029ae3403af7b17ef06e8a/gears_commands_test.go
@@ -9513,6 +9514,10 @@ func testAdapterCache(resp3 bool) {
95139514
resultAdd, err = adapter.TFunctionLoadArgs(ctx, libCodeWithConfig("lib2"), opt).Result()
95149515
Expect(err).NotTo(HaveOccurred())
95159516
Expect(resultAdd).To(BeEquivalentTo("OK"))
9517+
// Test nil options - should behave like TFunctionLoad
9518+
resultAdd, err = adapter.TFunctionLoadArgs(ctx, libCode("lib3"), nil).Result()
9519+
Expect(err).NotTo(HaveOccurred())
9520+
Expect(resultAdd).To(BeEquivalentTo("OK"))
95169521
})
95179522
It("should TFunctionList", Label("gears", "tfunctionlist"), func() {
95189523
resultAdd, err := adapter.TFunctionLoad(ctx, libCode("lib1")).Result()

0 commit comments

Comments
 (0)