From: Brian Aker Date: Fri, 11 Oct 2013 10:33:08 +0000 (-0700) Subject: Fix an error where client won't set error_message X-Git-Tag: 1.0.18~17^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=68f3c1df6d39eb2e507e32e18632f545dc2e923f;p=m6w6%2Flibmemcached Fix an error where client won't set error_message --- diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 04efe85d..eae44a90 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -54,7 +54,6 @@ static void auto_response(memcached_instance_st* instance, const bool reply, me if (memcached_fatal(rc)) { - fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, rc)); assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); *value= UINT64_MAX; } diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 2f16cbce..ab17926e 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -90,7 +90,7 @@ static void _set(Memcached& memc, memcached_string_t *str, memcached_return_t &r memcached_error_free(memc); } - if (memcached_fatal(rc)) + if (memcached_fatal(rc) or rc == MEMCACHED_CLIENT_ERROR) { // For memory allocation we use our error since it is a bit more specific if (local_errno == ENOMEM and rc == MEMCACHED_ERRNO) @@ -145,13 +145,28 @@ static void _set(Memcached& memc, memcached_string_t *str, memcached_return_t &r error->rc= rc; error->local_errno= local_errno; - const char *errmsg_ptr; - char errmsg[MAX_ERROR_LENGTH]; - errmsg[0]= 0; - errmsg_ptr= errmsg; + // MEMCACHED_CLIENT_ERROR is a special case because it is an error coming from the server + if (rc == MEMCACHED_CLIENT_ERROR) + { + assert(str); + assert(str->size); + if (str and str->size) + { + assert(error->local_errno == 0); + error->local_errno= 0; - if (local_errno) + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %.*s", + error->root, + int(str->size), str->c_str); + } + } + else if (local_errno) { + const char *errmsg_ptr; + char errmsg[MAX_ERROR_LENGTH]; + errmsg[0]= 0; + errmsg_ptr= errmsg; + #if defined(STRERROR_R_CHAR_P) && STRERROR_R_CHAR_P errmsg_ptr= strerror_r(local_errno, errmsg, sizeof(errmsg)); #elif defined(HAVE_STRERROR_R) && HAVE_STRERROR_R @@ -161,24 +176,23 @@ static void _set(Memcached& memc, memcached_string_t *str, memcached_return_t &r snprintf(errmsg, sizeof(errmsg), "%s", strerror(local_errno)); errmsg_ptr= errmsg; #endif - } - - if (str and str->size and local_errno) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s", - error->root, - memcached_strerror(&memc, rc), - errmsg_ptr, - memcached_string_printf(*str), at); - } - else if (local_errno) - { - error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s", - error->root, - memcached_strerror(&memc, rc), - errmsg_ptr, - at); + if (str and str->size and local_errno) + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s), %.*s -> %s", + error->root, + memcached_strerror(&memc, rc), + errmsg_ptr, + memcached_string_printf(*str), at); + } + else + { + error->size= (int)snprintf(error->message, MAX_ERROR_LENGTH, "(%p) %s(%s) -> %s", + error->root, + memcached_strerror(&memc, rc), + errmsg_ptr, + at); + } } else if (rc == MEMCACHED_PARSE_ERROR and str and str->size) { @@ -312,8 +326,8 @@ memcached_return_t memcached_set_error(memcached_instance_st& self, memcached_re { _set(*self.root, &error_host, rc, at); _set(self, (*self.root)); - assert(self.root->error_messages); assert(self.error_messages); + assert(self.root->error_messages); assert(self.error_messages->rc == self.root->error_messages->rc); } diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index 6bed25a9..4d4953ee 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -87,11 +87,13 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er static bool world_destroy(void *object) { libmemcached_test_container_st *container= (libmemcached_test_container_st *)object; +#if 0 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { sasl_done(); } +#endif #endif delete container; diff --git a/tests/libmemcached_world_socket.h b/tests/libmemcached_world_socket.h index 64cf55e5..69f0a91b 100644 --- a/tests/libmemcached_world_socket.h +++ b/tests/libmemcached_world_socket.h @@ -75,11 +75,14 @@ static void *world_create(libtest::server_startup_st& servers, test_return_t& er static bool world_destroy(void *object) { libmemcached_test_container_st *container= (libmemcached_test_container_st *)object; + +#if 0 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT if (LIBMEMCACHED_WITH_SASL_SUPPORT) { sasl_done(); } +#endif #endif delete container;