Skip to content

Commit a449493

Browse files
committed
Fix error message for maxStaleness with primary read preference
1 parent 5027842 commit a449493

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/MongoDB/ReadPreference.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,19 @@ static bool php_phongo_readpreference_init_from_hash(php_phongo_readpreference_t
9191

9292
if ((maxStalenessSeconds = zend_hash_str_find(props, "maxStalenessSeconds", sizeof("maxStalenessSeconds") - 1))) {
9393
if (Z_TYPE_P(maxStalenessSeconds) == IS_LONG) {
94-
if (Z_LVAL_P(maxStalenessSeconds) < MONGOC_SMALLEST_MAX_STALENESS_SECONDS) {
95-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_readpreference_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
96-
goto failure;
97-
}
98-
if (Z_LVAL_P(maxStalenessSeconds) > INT32_MAX) {
99-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_readpreference_ce->name), INT32_MAX);
100-
goto failure;
101-
}
102-
if (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY) {
103-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" array field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
104-
goto failure;
94+
if (Z_LVAL_P(maxStalenessSeconds) != MONGOC_NO_MAX_STALENESS) {
95+
if (mongoc_read_prefs_get_mode(intern->read_preference) == MONGOC_READ_PRIMARY) {
96+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" field to not be present with \"primary\" mode", ZSTR_VAL(php_phongo_readpreference_ce->name));
97+
goto failure;
98+
}
99+
if (Z_LVAL_P(maxStalenessSeconds) < MONGOC_SMALLEST_MAX_STALENESS_SECONDS) {
100+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" integer field to be >= %d", ZSTR_VAL(php_phongo_readpreference_ce->name), MONGOC_SMALLEST_MAX_STALENESS_SECONDS);
101+
goto failure;
102+
}
103+
if (Z_LVAL_P(maxStalenessSeconds) > INT32_MAX) {
104+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"maxStalenessSeconds\" integer field to be <= %" PRId32, ZSTR_VAL(php_phongo_readpreference_ce->name), INT32_MAX);
105+
goto failure;
106+
}
105107
}
106108

107109
mongoc_read_prefs_set_max_staleness_seconds(intern->read_preference, Z_LVAL_P(maxStalenessSeconds));

tests/readPreference/readpreference-set_state_error-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ MongoDB\Driver\ReadPreference initialization requires "tags" array field to not
6161
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6262
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" integer field to be >= 90
6363
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
64-
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" array field to not be present with "primary" mode
64+
MongoDB\Driver\ReadPreference initialization requires "maxStalenessSeconds" field to not be present with "primary" mode
6565
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
6666
MongoDB\Driver\ReadPreference initialization requires "hedge" field to be an array or object
6767
OK: Got MongoDB\Driver\Exception\InvalidArgumentException

0 commit comments

Comments
 (0)