Skip to content

Commit 068e3b3

Browse files
majiayu000claude
authored andcommitted
fix: distinguish between hooks and channels in RENAME error message
The RENAME command was incorrectly returning "key has hooks set" when a channel (not a hook) was associated with the key. This fix: - Adds a new error errKeyHasChannelsSet for channel-specific errors - Updates RENAME logic to check for hooks and channels separately - Returns the appropriate error message based on what's blocking the rename - Updates tests to expect "key has channels set" when channels are present Fixes #764 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 932631a commit 068e3b3

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

internal/server/crud.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,23 @@ func (s *Server) cmdRENAME(msg *Message) (resp.Value, commandDetails, error) {
479479
if col == nil {
480480
return retwerr(errKeyNotFound)
481481
}
482-
var ierr error
482+
var hasHook, hasChannel bool
483483
s.hooks.Ascend(nil, func(v interface{}) bool {
484484
h := v.(*Hook)
485485
if h.Key == key || h.Key == newKey {
486-
ierr = errKeyHasHooksSet
487-
return false
486+
if h.channel {
487+
hasChannel = true
488+
} else {
489+
hasHook = true
490+
}
488491
}
489492
return true
490493
})
491-
if ierr != nil {
492-
return retwerr(ierr)
494+
if hasHook {
495+
return retwerr(errKeyHasHooksSet)
496+
}
497+
if hasChannel {
498+
return retwerr(errKeyHasChannelsSet)
493499
}
494500
var updated bool
495501
newCol, _ := s.cols.Get(newKey)

internal/server/token.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var errIDNotFound = errors.New("id not found")
2121
var errIDAlreadyExists = errors.New("id already exists")
2222
var errPathNotFound = errors.New("path not found")
2323
var errKeyHasHooksSet = errors.New("key has hooks set")
24+
var errKeyHasChannelsSet = errors.New("key has channels set")
2425
var errNotRectangle = errors.New("not a rectangle")
2526

2627
func errInvalidArgument(arg string) error {

tests/keys_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func keys_RENAME_test(mc *mockServer) error {
113113
Do("RENAME", "foo", "mynewkey").Err("key not found"),
114114
Do("SCAN", "mynewkey", "COUNT").Str("1"),
115115
Do("SETCHAN", "mychan", "INTERSECTS", "mynewkey", "BOUNDS", 10, 10, 20, 20).Str("1"),
116-
Do("RENAME", "mynewkey", "foo2").Err("key has hooks set"),
117-
Do("RENAMENX", "mynewkey", "foo2").Err("key has hooks set"),
116+
Do("RENAME", "mynewkey", "foo2").Err("key has channels set"),
117+
Do("RENAMENX", "mynewkey", "foo2").Err("key has channels set"),
118118
Do("SET", "mykey", "myid1", "HASH", "9my5xp7").OK(),
119119
Do("RENAME", "mykey", "foo2").OK(),
120120
Do("RENAMENX", "foo2", "foo3").Str("1"),

0 commit comments

Comments
 (0)