Unverified Commit efaf09ee authored by Madelyn Olson's avatar Madelyn Olson Committed by GitHub
Browse files

Flow through the error handling path for most errors (#8226)

Properly throw errors for invalid replication stream and support https://github.com/redis/redis/pull/8217
parent 55abd1c6
...@@ -2224,7 +2224,7 @@ void addReplyCommandCategories(client *c, struct redisCommand *cmd) { ...@@ -2224,7 +2224,7 @@ void addReplyCommandCategories(client *c, struct redisCommand *cmd) {
void authCommand(client *c) { void authCommand(client *c) {
/* Only two or three argument forms are allowed. */ /* Only two or three argument forms are allowed. */
if (c->argc > 3) { if (c->argc > 3) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -611,7 +611,7 @@ void bitopCommand(client *c) { ...@@ -611,7 +611,7 @@ void bitopCommand(client *c) {
else if((opname[0] == 'n' || opname[0] == 'N') && !strcasecmp(opname,"not")) else if((opname[0] == 'n' || opname[0] == 'N') && !strcasecmp(opname,"not"))
op = BITOP_NOT; op = BITOP_NOT;
else { else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -813,7 +813,7 @@ void bitcountCommand(client *c) { ...@@ -813,7 +813,7 @@ void bitcountCommand(client *c) {
end = strlen-1; end = strlen-1;
} else { } else {
/* Syntax error. */ /* Syntax error. */
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -878,7 +878,7 @@ void bitposCommand(client *c) { ...@@ -878,7 +878,7 @@ void bitposCommand(client *c) {
end = strlen-1; end = strlen-1;
} else { } else {
/* Syntax error. */ /* Syntax error. */
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -970,7 +970,7 @@ void bitfieldGeneric(client *c, int flags) { ...@@ -970,7 +970,7 @@ void bitfieldGeneric(client *c, int flags) {
} }
continue; continue;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
zfree(ops); zfree(ops);
return; return;
} }
......
...@@ -200,9 +200,9 @@ void disconnectAllBlockedClients(void) { ...@@ -200,9 +200,9 @@ void disconnectAllBlockedClients(void) {
client *c = listNodeValue(ln); client *c = listNodeValue(ln);
if (c->flags & CLIENT_BLOCKED) { if (c->flags & CLIENT_BLOCKED) {
addReplySds(c,sdsnew( addReplyError(c,
"-UNBLOCKED force unblock from blocking operation, " "-UNBLOCKED force unblock from blocking operation, "
"instance state changed (master -> replica?)\r\n")); "instance state changed (master -> replica?)");
unblockClient(c); unblockClient(c);
c->flags |= CLIENT_CLOSE_AFTER_REPLY; c->flags |= CLIENT_CLOSE_AFTER_REPLY;
} }
......
...@@ -4820,7 +4820,7 @@ NULL ...@@ -4820,7 +4820,7 @@ NULL
takeover = 1; takeover = 1;
force = 1; /* Takeover also implies force. */ force = 1; /* Takeover also implies force. */
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -4911,7 +4911,7 @@ NULL ...@@ -4911,7 +4911,7 @@ NULL
} else if (!strcasecmp(c->argv[2]->ptr,"soft")) { } else if (!strcasecmp(c->argv[2]->ptr,"soft")) {
hard = 0; hard = 0;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -5049,7 +5049,7 @@ void restoreCommand(client *c) { ...@@ -5049,7 +5049,7 @@ void restoreCommand(client *c) {
} }
j++; /* Consume additional arg. */ j++; /* Consume additional arg. */
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -5057,7 +5057,7 @@ void restoreCommand(client *c) { ...@@ -5057,7 +5057,7 @@ void restoreCommand(client *c) {
/* Make sure this key does not already exist here... */ /* Make sure this key does not already exist here... */
robj *key = c->argv[1]; robj *key = c->argv[1];
if (!replace && lookupKeyWrite(c->db,key) != NULL) { if (!replace && lookupKeyWrite(c->db,key) != NULL) {
addReply(c,shared.busykeyerr); addReplyErrorObject(c,shared.busykeyerr);
return; return;
} }
...@@ -5170,8 +5170,7 @@ migrateCachedSocket* migrateGetSocket(client *c, robj *host, robj *port, long ti ...@@ -5170,8 +5170,7 @@ migrateCachedSocket* migrateGetSocket(client *c, robj *host, robj *port, long ti
conn = server.tls_cluster ? connCreateTLS() : connCreateSocket(); conn = server.tls_cluster ? connCreateTLS() : connCreateSocket();
if (connBlockingConnect(conn, c->argv[1]->ptr, atoi(c->argv[2]->ptr), timeout) if (connBlockingConnect(conn, c->argv[1]->ptr, atoi(c->argv[2]->ptr), timeout)
!= C_OK) { != C_OK) {
addReplySds(c, addReplyError(c,"-IOERR error or timeout connecting to the client");
sdsnew("-IOERR error or timeout connecting to the client\r\n"));
connClose(conn); connClose(conn);
sdsfree(name); sdsfree(name);
return NULL; return NULL;
...@@ -5259,14 +5258,14 @@ void migrateCommand(client *c) { ...@@ -5259,14 +5258,14 @@ void migrateCommand(client *c) {
replace = 1; replace = 1;
} else if (!strcasecmp(c->argv[j]->ptr,"auth")) { } else if (!strcasecmp(c->argv[j]->ptr,"auth")) {
if (!moreargs) { if (!moreargs) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
j++; j++;
password = c->argv[j]->ptr; password = c->argv[j]->ptr;
} else if (!strcasecmp(c->argv[j]->ptr,"auth2")) { } else if (!strcasecmp(c->argv[j]->ptr,"auth2")) {
if (moreargs < 2) { if (moreargs < 2) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
username = c->argv[++j]->ptr; username = c->argv[++j]->ptr;
...@@ -5282,7 +5281,7 @@ void migrateCommand(client *c) { ...@@ -5282,7 +5281,7 @@ void migrateCommand(client *c) {
num_keys = c->argc - j - 1; num_keys = c->argc - j - 1;
break; /* All the remaining args are keys. */ break; /* All the remaining args are keys. */
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -5837,23 +5836,23 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in ...@@ -5837,23 +5836,23 @@ clusterNode *getNodeByQuery(client *c, struct redisCommand *cmd, robj **argv, in
* be set to the hash slot that caused the redirection. */ * be set to the hash slot that caused the redirection. */
void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_code) { void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_code) {
if (error_code == CLUSTER_REDIR_CROSS_SLOT) { if (error_code == CLUSTER_REDIR_CROSS_SLOT) {
addReplySds(c,sdsnew("-CROSSSLOT Keys in request don't hash to the same slot\r\n")); addReplyError(c,"-CROSSSLOT Keys in request don't hash to the same slot");
} else if (error_code == CLUSTER_REDIR_UNSTABLE) { } else if (error_code == CLUSTER_REDIR_UNSTABLE) {
/* The request spawns multiple keys in the same slot, /* The request spawns multiple keys in the same slot,
* but the slot is not "stable" currently as there is * but the slot is not "stable" currently as there is
* a migration or import in progress. */ * a migration or import in progress. */
addReplySds(c,sdsnew("-TRYAGAIN Multiple keys request during rehashing of slot\r\n")); addReplyError(c,"-TRYAGAIN Multiple keys request during rehashing of slot");
} else if (error_code == CLUSTER_REDIR_DOWN_STATE) { } else if (error_code == CLUSTER_REDIR_DOWN_STATE) {
addReplySds(c,sdsnew("-CLUSTERDOWN The cluster is down\r\n")); addReplyError(c,"-CLUSTERDOWN The cluster is down");
} else if (error_code == CLUSTER_REDIR_DOWN_RO_STATE) { } else if (error_code == CLUSTER_REDIR_DOWN_RO_STATE) {
addReplySds(c,sdsnew("-CLUSTERDOWN The cluster is down and only accepts read commands\r\n")); addReplyError(c,"-CLUSTERDOWN The cluster is down and only accepts read commands");
} else if (error_code == CLUSTER_REDIR_DOWN_UNBOUND) { } else if (error_code == CLUSTER_REDIR_DOWN_UNBOUND) {
addReplySds(c,sdsnew("-CLUSTERDOWN Hash slot not served\r\n")); addReplyError(c,"-CLUSTERDOWN Hash slot not served");
} else if (error_code == CLUSTER_REDIR_MOVED || } else if (error_code == CLUSTER_REDIR_MOVED ||
error_code == CLUSTER_REDIR_ASK) error_code == CLUSTER_REDIR_ASK)
{ {
addReplySds(c,sdscatprintf(sdsempty(), addReplyErrorSds(c,sdscatprintf(sdsempty(),
"-%s %d %s:%d\r\n", "-%s %d %s:%d",
(error_code == CLUSTER_REDIR_ASK) ? "ASK" : "MOVED", (error_code == CLUSTER_REDIR_ASK) ? "ASK" : "MOVED",
hashslot,n->ip,n->port)); hashslot,n->ip,n->port));
} else { } else {
......
...@@ -593,7 +593,7 @@ int getFlushCommandFlags(client *c, int *flags) { ...@@ -593,7 +593,7 @@ int getFlushCommandFlags(client *c, int *flags) {
/* Parse the optional ASYNC option. */ /* Parse the optional ASYNC option. */
if (c->argc > 1) { if (c->argc > 1) {
if (c->argc > 2 || strcasecmp(c->argv[1]->ptr,"async")) { if (c->argc > 2 || strcasecmp(c->argv[1]->ptr,"async")) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return C_ERR; return C_ERR;
} }
*flags = EMPTYDB_ASYNC; *flags = EMPTYDB_ASYNC;
...@@ -842,7 +842,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) { ...@@ -842,7 +842,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
} }
if (count < 1) { if (count < 1) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
goto cleanup; goto cleanup;
} }
...@@ -861,7 +861,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) { ...@@ -861,7 +861,7 @@ void scanGenericCommand(client *c, robj *o, unsigned long cursor) {
typename = c->argv[i+1]->ptr; typename = c->argv[i+1]->ptr;
i+= 2; i+= 2;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
goto cleanup; goto cleanup;
} }
} }
...@@ -1050,7 +1050,7 @@ void shutdownCommand(client *c) { ...@@ -1050,7 +1050,7 @@ void shutdownCommand(client *c) {
int flags = 0; int flags = 0;
if (c->argc > 2) { if (c->argc > 2) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} else if (c->argc == 2) { } else if (c->argc == 2) {
if (!strcasecmp(c->argv[1]->ptr,"nosave")) { if (!strcasecmp(c->argv[1]->ptr,"nosave")) {
...@@ -1058,7 +1058,7 @@ void shutdownCommand(client *c) { ...@@ -1058,7 +1058,7 @@ void shutdownCommand(client *c) {
} else if (!strcasecmp(c->argv[1]->ptr,"save")) { } else if (!strcasecmp(c->argv[1]->ptr,"save")) {
flags |= SHUTDOWN_SAVE; flags |= SHUTDOWN_SAVE;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -1144,7 +1144,7 @@ void moveCommand(client *c) { ...@@ -1144,7 +1144,7 @@ void moveCommand(client *c) {
/* If the user is moving using as target the same /* If the user is moving using as target the same
* DB as the source DB it is probably an error. */ * DB as the source DB it is probably an error. */
if (src == dst) { if (src == dst) {
addReply(c,shared.sameobjecterr); addReplyErrorObject(c,shared.sameobjecterr);
return; return;
} }
...@@ -1224,7 +1224,7 @@ void copyCommand(client *c) { ...@@ -1224,7 +1224,7 @@ void copyCommand(client *c) {
robj *key = c->argv[1]; robj *key = c->argv[1];
robj *newkey = c->argv[2]; robj *newkey = c->argv[2];
if (src == dst && (sdscmp(key->ptr, newkey->ptr) == 0)) { if (src == dst && (sdscmp(key->ptr, newkey->ptr) == 0)) {
addReply(c,shared.sameobjecterr); addReplyErrorObject(c,shared.sameobjecterr);
return; return;
} }
......
...@@ -474,7 +474,7 @@ NULL ...@@ -474,7 +474,7 @@ NULL
rdbSaveInfo rsi, *rsiptr; rdbSaveInfo rsi, *rsiptr;
rsiptr = rdbPopulateSaveInfo(&rsi); rsiptr = rdbPopulateSaveInfo(&rsi);
if (rdbSave(server.rdb_filename,rsiptr) != C_OK) { if (rdbSave(server.rdb_filename,rsiptr) != C_OK) {
addReply(c,shared.err); addReplyErrorObject(c,shared.err);
return; return;
} }
} }
...@@ -500,7 +500,7 @@ NULL ...@@ -500,7 +500,7 @@ NULL
int ret = loadAppendOnlyFile(server.aof_filename); int ret = loadAppendOnlyFile(server.aof_filename);
unprotectClient(c); unprotectClient(c);
if (ret != C_OK) { if (ret != C_OK) {
addReply(c,shared.err); addReplyErrorObject(c,shared.err);
return; return;
} }
server.dirty = 0; /* Prevent AOF / replication */ server.dirty = 0; /* Prevent AOF / replication */
...@@ -512,7 +512,7 @@ NULL ...@@ -512,7 +512,7 @@ NULL
char *strenc; char *strenc;
if ((de = dictFind(c->db->dict,c->argv[2]->ptr)) == NULL) { if ((de = dictFind(c->db->dict,c->argv[2]->ptr)) == NULL) {
addReply(c,shared.nokeyerr); addReplyErrorObject(c,shared.nokeyerr);
return; return;
} }
val = dictGetVal(de); val = dictGetVal(de);
...@@ -564,7 +564,7 @@ NULL ...@@ -564,7 +564,7 @@ NULL
sds key; sds key;
if ((de = dictFind(c->db->dict,c->argv[2]->ptr)) == NULL) { if ((de = dictFind(c->db->dict,c->argv[2]->ptr)) == NULL) {
addReply(c,shared.nokeyerr); addReplyErrorObject(c,shared.nokeyerr);
return; return;
} }
val = dictGetVal(de); val = dictGetVal(de);
......
...@@ -100,8 +100,8 @@ int extractLongLatOrReply(client *c, robj **argv, double *xy) { ...@@ -100,8 +100,8 @@ int extractLongLatOrReply(client *c, robj **argv, double *xy) {
} }
if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX || if (xy[0] < GEO_LONG_MIN || xy[0] > GEO_LONG_MAX ||
xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) { xy[1] < GEO_LAT_MIN || xy[1] > GEO_LAT_MAX) {
addReplySds(c, sdscatprintf(sdsempty(), addReplyErrorFormat(c,
"-ERR invalid longitude,latitude pair %f,%f\r\n",xy[0],xy[1])); "-ERR invalid longitude,latitude pair %f,%f\r\n",xy[0],xy[1]);
return C_ERR; return C_ERR;
} }
return C_OK; return C_OK;
...@@ -902,7 +902,7 @@ void geodistCommand(client *c) { ...@@ -902,7 +902,7 @@ void geodistCommand(client *c) {
to_meter = extractUnitOrReply(c,c->argv[4]); to_meter = extractUnitOrReply(c,c->argv[4]);
if (to_meter < 0) return; if (to_meter < 0) return;
} else if (c->argc > 5) { } else if (c->argc > 5) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -205,7 +205,7 @@ struct hllhdr { ...@@ -205,7 +205,7 @@ struct hllhdr {
#define HLL_RAW 255 /* Only used internally, never exposed. */ #define HLL_RAW 255 /* Only used internally, never exposed. */
#define HLL_MAX_ENCODING 1 #define HLL_MAX_ENCODING 1
static char *invalid_hll_err = "-INVALIDOBJ Corrupted HLL object detected\r\n"; static char *invalid_hll_err = "-INVALIDOBJ Corrupted HLL object detected";
/* =========================== Low level bit macros ========================= */ /* =========================== Low level bit macros ========================= */
...@@ -1171,9 +1171,8 @@ int isHLLObjectOrReply(client *c, robj *o) { ...@@ -1171,9 +1171,8 @@ int isHLLObjectOrReply(client *c, robj *o) {
return C_OK; return C_OK;
invalid: invalid:
addReplySds(c, addReplyError(c,"-WRONGTYPE Key is not a valid "
sdsnew("-WRONGTYPE Key is not a valid " "HyperLogLog string value.");
"HyperLogLog string value.\r\n"));
return C_ERR; return C_ERR;
} }
...@@ -1203,7 +1202,7 @@ void pfaddCommand(client *c) { ...@@ -1203,7 +1202,7 @@ void pfaddCommand(client *c) {
updated++; updated++;
break; break;
case -1: case -1:
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
} }
...@@ -1245,7 +1244,7 @@ void pfcountCommand(client *c) { ...@@ -1245,7 +1244,7 @@ void pfcountCommand(client *c) {
/* Merge with this HLL with our 'max' HLL by setting max[i] /* Merge with this HLL with our 'max' HLL by setting max[i]
* to MAX(max[i],hll[i]). */ * to MAX(max[i],hll[i]). */
if (hllMerge(registers,o) == C_ERR) { if (hllMerge(registers,o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
} }
...@@ -1285,7 +1284,7 @@ void pfcountCommand(client *c) { ...@@ -1285,7 +1284,7 @@ void pfcountCommand(client *c) {
/* Recompute it and update the cached value. */ /* Recompute it and update the cached value. */
card = hllCount(hdr,&invalid); card = hllCount(hdr,&invalid);
if (invalid) { if (invalid) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
hdr->card[0] = card & 0xff; hdr->card[0] = card & 0xff;
...@@ -1332,7 +1331,7 @@ void pfmergeCommand(client *c) { ...@@ -1332,7 +1331,7 @@ void pfmergeCommand(client *c) {
/* Merge with this HLL with our 'max' HLL by setting max[i] /* Merge with this HLL with our 'max' HLL by setting max[i]
* to MAX(max[i],hll[i]). */ * to MAX(max[i],hll[i]). */
if (hllMerge(max,o) == C_ERR) { if (hllMerge(max,o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
} }
...@@ -1355,7 +1354,7 @@ void pfmergeCommand(client *c) { ...@@ -1355,7 +1354,7 @@ void pfmergeCommand(client *c) {
/* Convert the destination object to dense representation if at least /* Convert the destination object to dense representation if at least
* one of the inputs was dense. */ * one of the inputs was dense. */
if (use_dense && hllSparseToDense(o) == C_ERR) { if (use_dense && hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
...@@ -1512,7 +1511,7 @@ void pfdebugCommand(client *c) { ...@@ -1512,7 +1511,7 @@ void pfdebugCommand(client *c) {
if (hdr->encoding == HLL_SPARSE) { if (hdr->encoding == HLL_SPARSE) {
if (hllSparseToDense(o) == C_ERR) { if (hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
server.dirty++; /* Force propagation on encoding change. */ server.dirty++; /* Force propagation on encoding change. */
...@@ -1577,7 +1576,7 @@ void pfdebugCommand(client *c) { ...@@ -1577,7 +1576,7 @@ void pfdebugCommand(client *c) {
if (hdr->encoding == HLL_SPARSE) { if (hdr->encoding == HLL_SPARSE) {
if (hllSparseToDense(o) == C_ERR) { if (hllSparseToDense(o) == C_ERR) {
addReplySds(c,sdsnew(invalid_hll_err)); addReplyError(c,invalid_hll_err);
return; return;
} }
conv = 1; conv = 1;
......
...@@ -2427,7 +2427,7 @@ NULL ...@@ -2427,7 +2427,7 @@ NULL
} }
} }
} else if (c->argc != 2) { } else if (c->argc != 2) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -2446,7 +2446,7 @@ NULL ...@@ -2446,7 +2446,7 @@ NULL
if (!(c->flags & CLIENT_REPLY_OFF)) if (!(c->flags & CLIENT_REPLY_OFF))
c->flags |= CLIENT_REPLY_SKIP_NEXT; c->flags |= CLIENT_REPLY_SKIP_NEXT;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} else if (!strcasecmp(c->argv[1]->ptr,"kill")) { } else if (!strcasecmp(c->argv[1]->ptr,"kill")) {
...@@ -2502,17 +2502,17 @@ NULL ...@@ -2502,17 +2502,17 @@ NULL
} else if (!strcasecmp(c->argv[i+1]->ptr,"no")) { } else if (!strcasecmp(c->argv[i+1]->ptr,"no")) {
skipme = 0; skipme = 0;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
i += 2; i += 2;
} }
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -2649,7 +2649,7 @@ NULL ...@@ -2649,7 +2649,7 @@ NULL
prefix[numprefix++] = c->argv[j]; prefix[numprefix++] = c->argv[j];
} else { } else {
zfree(prefix); zfree(prefix);
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -2711,7 +2711,7 @@ NULL ...@@ -2711,7 +2711,7 @@ NULL
disableTracking(c); disableTracking(c);
} else { } else {
zfree(prefix); zfree(prefix);
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
zfree(prefix); zfree(prefix);
...@@ -2740,7 +2740,7 @@ NULL ...@@ -2740,7 +2740,7 @@ NULL
return; return;
} }
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -404,7 +404,7 @@ robj *resetRefCount(robj *obj) { ...@@ -404,7 +404,7 @@ robj *resetRefCount(robj *obj) {
int checkType(client *c, robj *o, int type) { int checkType(client *c, robj *o, int type) {
/* A NULL is considered an empty key */ /* A NULL is considered an empty key */
if (o && o->type != type) { if (o && o->type != type) {
addReply(c,shared.wrongtypeerr); addReplyErrorObject(c,shared.wrongtypeerr);
return 1; return 1;
} }
return 0; return 0;
...@@ -1321,13 +1321,13 @@ NULL ...@@ -1321,13 +1321,13 @@ NULL
if (getLongLongFromObjectOrReply(c,c->argv[j+1],&samples,NULL) if (getLongLongFromObjectOrReply(c,c->argv[j+1],&samples,NULL)
== C_ERR) return; == C_ERR) return;
if (samples < 0) { if (samples < 0) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
if (samples == 0) samples = LLONG_MAX; if (samples == 0) samples = LLONG_MAX;
j++; /* skip option argument. */ j++; /* skip option argument. */
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
......
...@@ -2852,7 +2852,7 @@ void saveCommand(client *c) { ...@@ -2852,7 +2852,7 @@ void saveCommand(client *c) {
if (rdbSave(server.rdb_filename,rsiptr) == C_OK) { if (rdbSave(server.rdb_filename,rsiptr) == C_OK) {
addReply(c,shared.ok); addReply(c,shared.ok);
} else { } else {
addReply(c,shared.err); addReplyErrorObject(c,shared.err);
} }
} }
...@@ -2866,7 +2866,7 @@ void bgsaveCommand(client *c) { ...@@ -2866,7 +2866,7 @@ void bgsaveCommand(client *c) {
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"schedule")) { if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"schedule")) {
schedule = 1; schedule = 1;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -2889,7 +2889,7 @@ void bgsaveCommand(client *c) { ...@@ -2889,7 +2889,7 @@ void bgsaveCommand(client *c) {
} else if (rdbSaveBackground(server.rdb_filename,rsiptr) == C_OK) { } else if (rdbSaveBackground(server.rdb_filename,rsiptr) == C_OK) {
addReplyStatus(c,"Background saving started"); addReplyStatus(c,"Background saving started");
} else { } else {
addReply(c,shared.err); addReplyErrorObject(c,shared.err);
} }
} }
......
...@@ -715,7 +715,7 @@ void syncCommand(client *c) { ...@@ -715,7 +715,7 @@ void syncCommand(client *c) {
/* Refuse SYNC requests if we are a slave but the link with our master /* Refuse SYNC requests if we are a slave but the link with our master
* is not ok... */ * is not ok... */
if (server.masterhost && server.repl_state != REPL_STATE_CONNECTED) { if (server.masterhost && server.repl_state != REPL_STATE_CONNECTED) {
addReplySds(c,sdsnew("-NOMASTERLINK Can't SYNC while not connected with my master\r\n")); addReplyError(c,"-NOMASTERLINK Can't SYNC while not connected with my master");
return; return;
} }
...@@ -866,7 +866,7 @@ void replconfCommand(client *c) { ...@@ -866,7 +866,7 @@ void replconfCommand(client *c) {
if ((c->argc % 2) == 0) { if ((c->argc % 2) == 0) {
/* Number of arguments must be odd to make sure that every /* Number of arguments must be odd to make sure that every
* option has a corresponding value. */ * option has a corresponding value. */
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -368,7 +368,7 @@ void luaReplyToRedisReply(client *c, lua_State *lua) { ...@@ -368,7 +368,7 @@ void luaReplyToRedisReply(client *c, lua_State *lua) {
if (t == LUA_TSTRING) { if (t == LUA_TSTRING) {
sds err = sdsnew(lua_tostring(lua,-1)); sds err = sdsnew(lua_tostring(lua,-1));
sdsmapchars(err,"\r\n"," ",2); sdsmapchars(err,"\r\n"," ",2);
addReplySds(c,sdscatprintf(sdsempty(),"-%s\r\n",err)); addReplyErrorSds(c,sdscatprintf(sdsempty(),"-%s",err));
sdsfree(err); sdsfree(err);
lua_pop(lua,2); lua_pop(lua,2);
return; return;
...@@ -1740,11 +1740,11 @@ NULL ...@@ -1740,11 +1740,11 @@ NULL
forceCommandPropagation(c,PROPAGATE_REPL|PROPAGATE_AOF); forceCommandPropagation(c,PROPAGATE_REPL|PROPAGATE_AOF);
} else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"kill")) { } else if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"kill")) {
if (server.lua_caller == NULL) { if (server.lua_caller == NULL) {
addReplySds(c,sdsnew("-NOTBUSY No scripts in execution right now.\r\n")); addReplyError(c,"-NOTBUSY No scripts in execution right now.");
} else if (server.lua_caller->flags & CLIENT_MASTER) { } else if (server.lua_caller->flags & CLIENT_MASTER) {
addReplySds(c,sdsnew("-UNKILLABLE The busy script was sent by a master instance in the context of replication and cannot be killed.\r\n")); addReplyError(c,"-UNKILLABLE The busy script was sent by a master instance in the context of replication and cannot be killed.");
} else if (server.lua_write_dirty) { } else if (server.lua_write_dirty) {
addReplySds(c,sdsnew("-UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.\r\n")); addReplyError(c,"-UNKILLABLE Sorry the script already executed write commands against the dataset. You can either wait the script termination or kill the server in a hard way using the SHUTDOWN NOSAVE command.");
} else { } else {
server.lua_kill = 1; server.lua_kill = 1;
addReply(c,shared.ok); addReply(c,shared.ok);
......
...@@ -3446,7 +3446,7 @@ numargserr: ...@@ -3446,7 +3446,7 @@ numargserr:
/* SENTINEL INFO [section] */ /* SENTINEL INFO [section] */
void sentinelInfoCommand(client *c) { void sentinelInfoCommand(client *c) {
if (c->argc > 2) { if (c->argc > 2) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -2380,9 +2380,9 @@ void afterSleep(struct aeEventLoop *eventLoop) { ...@@ -2380,9 +2380,9 @@ void afterSleep(struct aeEventLoop *eventLoop) {
void createSharedObjects(void) { void createSharedObjects(void) {
int j; int j;
/* Shared command responses */
shared.crlf = createObject(OBJ_STRING,sdsnew("\r\n")); shared.crlf = createObject(OBJ_STRING,sdsnew("\r\n"));
shared.ok = createObject(OBJ_STRING,sdsnew("+OK\r\n")); shared.ok = createObject(OBJ_STRING,sdsnew("+OK\r\n"));
shared.err = createObject(OBJ_STRING,sdsnew("-ERR\r\n"));
shared.emptybulk = createObject(OBJ_STRING,sdsnew("$0\r\n\r\n")); shared.emptybulk = createObject(OBJ_STRING,sdsnew("$0\r\n\r\n"));
shared.czero = createObject(OBJ_STRING,sdsnew(":0\r\n")); shared.czero = createObject(OBJ_STRING,sdsnew(":0\r\n"));
shared.cone = createObject(OBJ_STRING,sdsnew(":1\r\n")); shared.cone = createObject(OBJ_STRING,sdsnew(":1\r\n"));
...@@ -2390,8 +2390,14 @@ void createSharedObjects(void) { ...@@ -2390,8 +2390,14 @@ void createSharedObjects(void) {
shared.pong = createObject(OBJ_STRING,sdsnew("+PONG\r\n")); shared.pong = createObject(OBJ_STRING,sdsnew("+PONG\r\n"));
shared.queued = createObject(OBJ_STRING,sdsnew("+QUEUED\r\n")); shared.queued = createObject(OBJ_STRING,sdsnew("+QUEUED\r\n"));
shared.emptyscan = createObject(OBJ_STRING,sdsnew("*2\r\n$1\r\n0\r\n*0\r\n")); shared.emptyscan = createObject(OBJ_STRING,sdsnew("*2\r\n$1\r\n0\r\n*0\r\n"));
shared.space = createObject(OBJ_STRING,sdsnew(" "));
shared.colon = createObject(OBJ_STRING,sdsnew(":"));
shared.plus = createObject(OBJ_STRING,sdsnew("+"));
/* Shared command error responses */
shared.wrongtypeerr = createObject(OBJ_STRING,sdsnew( shared.wrongtypeerr = createObject(OBJ_STRING,sdsnew(
"-WRONGTYPE Operation against a key holding the wrong kind of value\r\n")); "-WRONGTYPE Operation against a key holding the wrong kind of value\r\n"));
shared.err = createObject(OBJ_STRING,sdsnew("-ERR\r\n"));
shared.nokeyerr = createObject(OBJ_STRING,sdsnew( shared.nokeyerr = createObject(OBJ_STRING,sdsnew(
"-ERR no such key\r\n")); "-ERR no such key\r\n"));
shared.syntaxerr = createObject(OBJ_STRING,sdsnew( shared.syntaxerr = createObject(OBJ_STRING,sdsnew(
...@@ -2422,9 +2428,6 @@ void createSharedObjects(void) { ...@@ -2422,9 +2428,6 @@ void createSharedObjects(void) {
"-NOREPLICAS Not enough good replicas to write.\r\n")); "-NOREPLICAS Not enough good replicas to write.\r\n"));
shared.busykeyerr = createObject(OBJ_STRING,sdsnew( shared.busykeyerr = createObject(OBJ_STRING,sdsnew(
"-BUSYKEY Target key name already exists.\r\n")); "-BUSYKEY Target key name already exists.\r\n"));
shared.space = createObject(OBJ_STRING,sdsnew(" "));
shared.colon = createObject(OBJ_STRING,sdsnew(":"));
shared.plus = createObject(OBJ_STRING,sdsnew("+"));
/* The shared NULL depends on the protocol version. */ /* The shared NULL depends on the protocol version. */
shared.null[0] = NULL; shared.null[0] = NULL;
...@@ -4956,7 +4959,7 @@ void infoCommand(client *c) { ...@@ -4956,7 +4959,7 @@ void infoCommand(client *c) {
char *section = c->argc == 2 ? c->argv[1]->ptr : "default"; char *section = c->argc == 2 ? c->argv[1]->ptr : "default";
if (c->argc > 2) { if (c->argc > 2) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
sds info = genRedisInfoString(section); sds info = genRedisInfoString(section);
......
...@@ -256,7 +256,7 @@ void sortCommand(client *c) { ...@@ -256,7 +256,7 @@ void sortCommand(client *c) {
getop++; getop++;
j++; j++;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
syntax_error++; syntax_error++;
break; break;
} }
...@@ -279,7 +279,7 @@ void sortCommand(client *c) { ...@@ -279,7 +279,7 @@ void sortCommand(client *c) {
sortval->type != OBJ_ZSET) sortval->type != OBJ_ZSET)
{ {
listRelease(operations); listRelease(operations);
addReply(c,shared.wrongtypeerr); addReplyErrorObject(c,shared.wrongtypeerr);
return; return;
} }
......
...@@ -294,7 +294,7 @@ void linsertCommand(client *c) { ...@@ -294,7 +294,7 @@ void linsertCommand(client *c) {
} else if (strcasecmp(c->argv[2]->ptr,"before") == 0) { } else if (strcasecmp(c->argv[2]->ptr,"before") == 0) {
where = LIST_HEAD; where = LIST_HEAD;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -373,7 +373,7 @@ void lsetCommand(client *c) { ...@@ -373,7 +373,7 @@ void lsetCommand(client *c) {
int replaced = quicklistReplaceAtIndex(ql, index, int replaced = quicklistReplaceAtIndex(ql, index,
value->ptr, sdslen(value->ptr)); value->ptr, sdslen(value->ptr));
if (!replaced) { if (!replaced) {
addReply(c,shared.outofrangeerr); addReplyErrorObject(c,shared.outofrangeerr);
} else { } else {
addReply(c,shared.ok); addReply(c,shared.ok);
signalModifiedKey(c,c->db,c->argv[1]); signalModifiedKey(c,c->db,c->argv[1]);
...@@ -566,7 +566,7 @@ void lposCommand(client *c) { ...@@ -566,7 +566,7 @@ void lposCommand(client *c) {
return; return;
} }
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -698,7 +698,7 @@ int getListPositionFromObjectOrReply(client *c, robj *arg, int *position) { ...@@ -698,7 +698,7 @@ int getListPositionFromObjectOrReply(client *c, robj *arg, int *position) {
} else if (strcasecmp(arg->ptr,"left") == 0) { } else if (strcasecmp(arg->ptr,"left") == 0) {
*position = LIST_HEAD; *position = LIST_HEAD;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return C_ERR; return C_ERR;
} }
return C_OK; return C_OK;
......
...@@ -605,7 +605,7 @@ void spopCommand(client *c) { ...@@ -605,7 +605,7 @@ void spopCommand(client *c) {
spopWithCountCommand(c); spopWithCountCommand(c);
return; return;
} else if (c->argc > 3) { } else if (c->argc > 3) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -801,7 +801,7 @@ void srandmemberCommand(client *c) { ...@@ -801,7 +801,7 @@ void srandmemberCommand(client *c) {
srandmemberWithCountCommand(c); srandmemberWithCountCommand(c);
return; return;
} else if (c->argc > 3) { } else if (c->argc > 3) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
......
...@@ -1534,7 +1534,7 @@ void xrangeGenericCommand(client *c, int rev) { ...@@ -1534,7 +1534,7 @@ void xrangeGenericCommand(client *c, int rev) {
if (count < 0) count = 0; if (count < 0) count = 0;
j++; /* Consume additional arg. */ j++; /* Consume additional arg. */
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -1643,14 +1643,14 @@ void xreadCommand(client *c) { ...@@ -1643,14 +1643,14 @@ void xreadCommand(client *c) {
} }
noack = 1; noack = 1;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
/* STREAMS option is mandatory. */ /* STREAMS option is mandatory. */
if (streams_arg == 0) { if (streams_arg == 0) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -2076,8 +2076,7 @@ NULL ...@@ -2076,8 +2076,7 @@ NULL
notifyKeyspaceEvent(NOTIFY_STREAM,"xgroup-create", notifyKeyspaceEvent(NOTIFY_STREAM,"xgroup-create",
c->argv[2],c->db->id); c->argv[2],c->db->id);
} else { } else {
addReplySds(c, addReplyError(c,"-BUSYGROUP Consumer Group name already exists");
sdsnew("-BUSYGROUP Consumer Group name already exists\r\n"));
} }
} else if (!strcasecmp(opt,"SETID") && c->argc == 5) { } else if (!strcasecmp(opt,"SETID") && c->argc == 5) {
streamID id; streamID id;
...@@ -2237,7 +2236,7 @@ void xpendingCommand(client *c) { ...@@ -2237,7 +2236,7 @@ void xpendingCommand(client *c) {
/* Start and stop, and the consumer, can be omitted. Also the IDLE modifier. */ /* Start and stop, and the consumer, can be omitted. Also the IDLE modifier. */
if (c->argc != 3 && (c->argc < 6 || c->argc > 9)) { if (c->argc != 3 && (c->argc < 6 || c->argc > 9)) {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
...@@ -2251,7 +2250,7 @@ void xpendingCommand(client *c) { ...@@ -2251,7 +2250,7 @@ void xpendingCommand(client *c) {
return; return;
if (c->argc < 8) { if (c->argc < 8) {
/* If IDLE was provided we must have at least 'start end count' */ /* If IDLE was provided we must have at least 'start end count' */
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
/* Search for rest of arguments after 'IDLE <idle>' */ /* Search for rest of arguments after 'IDLE <idle>' */
...@@ -2758,7 +2757,7 @@ void xtrimCommand(client *c) { ...@@ -2758,7 +2757,7 @@ void xtrimCommand(client *c) {
i++; i++;
maxlen_arg_idx = i; maxlen_arg_idx = i;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
......
...@@ -153,7 +153,7 @@ void setCommand(client *c) { ...@@ -153,7 +153,7 @@ void setCommand(client *c) {
expire = next; expire = next;
j++; j++;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
return; return;
} }
} }
...@@ -528,7 +528,7 @@ void stralgoCommand(client *c) { ...@@ -528,7 +528,7 @@ void stralgoCommand(client *c) {
if (!strcasecmp(c->argv[1]->ptr,"lcs")) { if (!strcasecmp(c->argv[1]->ptr,"lcs")) {
stralgoLCS(c); stralgoLCS(c);
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
} }
} }
...@@ -589,7 +589,7 @@ void stralgoLCS(client *c) { ...@@ -589,7 +589,7 @@ void stralgoLCS(client *c) {
b = objb->ptr; b = objb->ptr;
j += 2; j += 2;
} else { } else {
addReply(c,shared.syntaxerr); addReplyErrorObject(c,shared.syntaxerr);
goto cleanup; goto cleanup;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment