Skip to content

Commit e21bc63

Browse files
committed
Merge branch 'error-throw' into develop
2 parents cb2c4d6 + e372398 commit e21bc63

File tree

2 files changed

+13
-34
lines changed

2 files changed

+13
-34
lines changed

common.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,6 @@ typedef enum _PUBSUB_TYPE {
454454
#define BITOP_MIN_OFFSET 0
455455
#define BITOP_MAX_OFFSET 4294967295U
456456

457-
/* Specific error messages we want to throw against */
458-
#define REDIS_ERR_LOADING_MSG "LOADING Redis is loading the dataset in memory"
459-
#define REDIS_ERR_LOADING_KW "LOADING"
460-
#define REDIS_ERR_AUTH_MSG "NOAUTH Authentication required."
461-
#define REDIS_ERR_AUTH_KW "NOAUTH"
462-
#define REDIS_ERR_SYNC_MSG "MASTERDOWN Link with MASTER is down and slave-serve-stale-data is set to 'no'"
463-
#define REDIS_ERR_SYNC_KW "MASTERDOWN"
464-
465457
#define IF_ATOMIC() if (redis_sock->mode == ATOMIC)
466458
#define IF_NOT_ATOMIC() if (redis_sock->mode != ATOMIC)
467459
#define IF_MULTI() if (redis_sock->mode == MULTI)

library.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,15 @@ static int resend_auth(RedisSock *redis_sock TSRMLS_DC) {
112112
* 2) AUTH
113113
* 3) LOADING
114114
*/
115-
static void redis_error_throw(char *err, size_t err_len TSRMLS_DC) {
116-
/* Handle stale data error (slave syncing with master) */
117-
if (err_len == sizeof(REDIS_ERR_SYNC_MSG) - 1 &&
118-
!memcmp(err,REDIS_ERR_SYNC_KW,sizeof(REDIS_ERR_SYNC_KW)-1))
119-
{
120-
zend_throw_exception(redis_exception_ce,
121-
"SYNC with master in progress or master down!", 0 TSRMLS_CC);
122-
} else if (err_len == sizeof(REDIS_ERR_LOADING_MSG) - 1 &&
123-
!memcmp(err,REDIS_ERR_LOADING_KW,sizeof(REDIS_ERR_LOADING_KW)-1))
124-
{
125-
zend_throw_exception(redis_exception_ce,
126-
"Redis is LOADING the dataset", 0 TSRMLS_CC);
127-
} else if (err_len == sizeof(REDIS_ERR_AUTH_MSG) -1 &&
128-
!memcmp(err,REDIS_ERR_AUTH_KW,sizeof(REDIS_ERR_AUTH_KW)-1))
129-
{
130-
zend_throw_exception(redis_exception_ce,
131-
"Failed to AUTH connection", 0 TSRMLS_CC);
115+
static void
116+
redis_error_throw(RedisSock *redis_sock TSRMLS_DC)
117+
{
118+
if (redis_sock != NULL && redis_sock->err != NULL &&
119+
memcmp(redis_sock->err, "ERR", sizeof("ERR") - 1) != 0 &&
120+
memcmp(redis_sock->err, "NOSCRIPT", sizeof("NOSCRIPT") - 1) != 0 &&
121+
memcmp(redis_sock->err, "WRONGTYPE", sizeof("WRONGTYPE") - 1) != 0
122+
) {
123+
zend_throw_exception(redis_exception_ce, redis_sock->err, 0 TSRMLS_CC);
132124
}
133125
}
134126

@@ -513,13 +505,8 @@ redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
513505
redis_sock_set_err(redis_sock, inbuf+1, len);
514506

515507
/* Filter our ERROR through the few that should actually throw */
516-
redis_error_throw(inbuf + 1, len TSRMLS_CC);
508+
redis_error_throw(redis_sock TSRMLS_CC);
517509

518-
/* Handle stale data error */
519-
if(memcmp(inbuf + 1, "-ERR SYNC ", 10) == 0) {
520-
zend_throw_exception(redis_exception_ce,
521-
"SYNC with master in progress", 0 TSRMLS_CC);
522-
}
523510
return NULL;
524511
case '$':
525512
*buf_len = atoi(inbuf + 1);
@@ -2159,12 +2146,12 @@ redis_read_variant_line(RedisSock *redis_sock, REDIS_REPLY_TYPE reply_type,
21592146
// If this is an error response, check if it is a SYNC error, and throw in
21602147
// that case
21612148
if(reply_type == TYPE_ERR) {
2162-
/* Handle throwable errors */
2163-
redis_error_throw(inbuf, line_size TSRMLS_CC);
2164-
21652149
/* Set our last error */
21662150
redis_sock_set_err(redis_sock, inbuf, line_size);
21672151

2152+
/* Handle throwable errors */
2153+
redis_error_throw(redis_sock TSRMLS_CC);
2154+
21682155
/* Set our response to FALSE */
21692156
ZVAL_FALSE(z_ret);
21702157
} else {

0 commit comments

Comments
 (0)