summaryrefslogtreecommitdiff
path: root/src/call_reply.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/call_reply.c')
-rw-r--r--src/call_reply.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/call_reply.c b/src/call_reply.c
index 3694db55e..759cd792a 100644
--- a/src/call_reply.c
+++ b/src/call_reply.c
@@ -525,3 +525,18 @@ CallReply *callReplyCreate(sds reply, list *deferred_error_list, void *private_d
res->deferred_error_list = deferred_error_list;
return res;
}
+
+/* Create a new CallReply struct from the reply blob representing an error message.
+ * Automatically creating deferred_error_list and set a copy of the reply in it.
+ * Refer to callReplyCreate for detailed explanation. */
+CallReply *callReplyCreateError(sds reply, void *private_data) {
+ sds err_buff = reply;
+ if (err_buff[0] != '-') {
+ err_buff = sdscatfmt(sdsempty(), "-ERR %S\r\n", reply);
+ sdsfree(reply);
+ }
+ list *deferred_error_list = listCreate();
+ listSetFreeMethod(deferred_error_list, (void (*)(void*))sdsfree);
+ listAddNodeTail(deferred_error_list, sdsnew(err_buff));
+ return callReplyCreate(err_buff, deferred_error_list, private_data);
+}