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
This commit is contained in:
Yang Bodong 2021-04-07 15:01:28 +08:00 committed by GitHub
parent 4de1031d8a
commit 4c14e8668c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -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) { int getPositiveLongFromObjectOrReply(client *c, robj *o, long *target, const char *msg) {
if (msg) {
return getRangeLongFromObjectOrReply(c, o, 0, LONG_MAX, target, 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) { int getIntFromObjectOrReply(client *c, robj *o, int *target, const char *msg) {

View File

@ -3051,12 +3051,8 @@ void xautoclaimCommand(client *c) {
int moreargs = (c->argc-1) - j; /* Number of additional arguments. */ int moreargs = (c->argc-1) - j; /* Number of additional arguments. */
char *opt = c->argv[j]->ptr; char *opt = c->argv[j]->ptr;
if (!strcasecmp(opt,"COUNT") && moreargs) { 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; return;
if (count == 0) {
addReplyError(c,"COUNT must be > 0");
return;
}
j++; j++;
} else if (!strcasecmp(opt,"JUSTID")) { } else if (!strcasecmp(opt,"JUSTID")) {
justid = 1; justid = 1;

View File

@ -462,6 +462,10 @@ start_server {
assert_equal [lindex $reply 1 0 1] {e 5} 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} { test {XINFO FULL output} {
r del x r del x
r XADD x 100 a 1 r XADD x 100 a 1