From 4c14e8668cdfa6a967fd3be6e0a159d1156b7ef6 Mon Sep 17 00:00:00 2001 From: Yang Bodong Date: Wed, 7 Apr 2021 15:01:28 +0800 Subject: [PATCH] Fix out of range confusing error messages (XAUTOCLAIM, RPOP count) (#8746) Fix out of range error messages to be clearer (avoid mentioning 9223372036854775807) * Fix XAUTOCLAIM COUNT option confusing error msg * Fix other RPOP and alike error message to mention positive --- src/object.c | 6 +++++- src/t_stream.c | 6 +----- tests/unit/type/stream-cgroups.tcl | 4 ++++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/object.c b/src/object.c index ce2f3dc14..b75e547b9 100644 --- a/src/object.c +++ b/src/object.c @@ -727,7 +727,11 @@ int getRangeLongFromObjectOrReply(client *c, robj *o, long min, long max, long * } int getPositiveLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg) { - return getRangeLongFromObjectOrReply(c, o, 0, LONG_MAX, target, msg); + if (msg) { + return getRangeLongFromObjectOrReply(c, o, 0, LONG_MAX, target, msg); + } else { + return getRangeLongFromObjectOrReply(c, o, 0, LONG_MAX, target, "value is out of range, must be positive"); + } } int getIntFromObjectOrReply(client *c, robj *o, int *target, const char *msg) { diff --git a/src/t_stream.c b/src/t_stream.c index f175eed9a..c0283f3e9 100644 --- a/src/t_stream.c +++ b/src/t_stream.c @@ -3051,12 +3051,8 @@ void xautoclaimCommand(client *c) { int moreargs = (c->argc-1) - j; /* Number of additional arguments. */ char *opt = c->argv[j]->ptr; if (!strcasecmp(opt,"COUNT") && moreargs) { - if (getPositiveLongFromObjectOrReply(c,c->argv[j+1],&count,NULL) != C_OK) + if (getRangeLongFromObjectOrReply(c,c->argv[j+1],1,LONG_MAX,&count,"COUNT must be > 0") != C_OK) return; - if (count == 0) { - addReplyError(c,"COUNT must be > 0"); - return; - } j++; } else if (!strcasecmp(opt,"JUSTID")) { justid = 1; diff --git a/tests/unit/type/stream-cgroups.tcl b/tests/unit/type/stream-cgroups.tcl index 53eb46ca3..edc5af6bd 100644 --- a/tests/unit/type/stream-cgroups.tcl +++ b/tests/unit/type/stream-cgroups.tcl @@ -462,6 +462,10 @@ start_server { assert_equal [lindex $reply 1 0 1] {e 5} } + test {XAUTOCLAIM COUNT must be > 0} { + assert_error "ERR COUNT must be > 0" {r XAUTOCLAIM key group consumer 1 1 COUNT 0} + } + test {XINFO FULL output} { r del x r XADD x 100 a 1