From af52e89e0706fd42b4c8ff13eeedb48e8afac3a0 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Wed, 11 Feb 2026 14:34:27 -0500 Subject: [PATCH] PHPC-2689: Throw LogicException in Binary::getVectorType() and toArray() --- src/BSON/Binary.c | 4 ++-- .../bson-binary-getvectortype_error-001.phpt | 18 ++++++++++++++++++ tests/bson/bson-binary-toarray_error-001.phpt | 18 ++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 tests/bson/bson-binary-getvectortype_error-001.phpt create mode 100644 tests/bson/bson-binary-toarray_error-001.phpt diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 64fc4a90a..5cefb5f27 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -548,7 +548,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, getVectorType) php_phongo_binary_t* intern = Z_BINARY_OBJ_P(getThis()); if (intern->type != BSON_SUBTYPE_VECTOR) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected Binary of type vector (%" PRId8 ") but it is %" PHONGO_LONG_FORMAT, BSON_SUBTYPE_VECTOR, intern->type); + phongo_throw_exception(PHONGO_ERROR_LOGIC, "Expected Binary of type vector (%" PRId8 ") but it is %" PHONGO_LONG_FORMAT, BSON_SUBTYPE_VECTOR, intern->type); RETURN_THROWS(); } @@ -655,7 +655,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, toArray) php_phongo_binary_t* intern = Z_BINARY_OBJ_P(getThis()); if (intern->type != BSON_SUBTYPE_VECTOR) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected Binary of type vector (%" PRId8 ") but it is %" PHONGO_LONG_FORMAT, BSON_SUBTYPE_VECTOR, intern->type); + phongo_throw_exception(PHONGO_ERROR_LOGIC, "Expected Binary of type vector (%" PRId8 ") but it is %" PHONGO_LONG_FORMAT, BSON_SUBTYPE_VECTOR, intern->type); RETURN_THROWS(); } diff --git a/tests/bson/bson-binary-getvectortype_error-001.phpt b/tests/bson/bson-binary-getvectortype_error-001.phpt new file mode 100644 index 000000000..d5448c0d5 --- /dev/null +++ b/tests/bson/bson-binary-getvectortype_error-001.phpt @@ -0,0 +1,18 @@ +--TEST-- +MongoDB\BSON\Binary::getVectorType() requires vector subtype +--FILE-- +getVectorType(); +}, 'MongoDB\Driver\Exception\LogicException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +Expected Binary of type vector (9) but it is 0 +===DONE=== diff --git a/tests/bson/bson-binary-toarray_error-001.phpt b/tests/bson/bson-binary-toarray_error-001.phpt new file mode 100644 index 000000000..f015ee7ab --- /dev/null +++ b/tests/bson/bson-binary-toarray_error-001.phpt @@ -0,0 +1,18 @@ +--TEST-- +MongoDB\BSON\Binary::toArray() requires vector subtype +--FILE-- +toArray(); +}, 'MongoDB\Driver\Exception\LogicException'), "\n"; + +?> +===DONE=== + +--EXPECT-- +OK: Got MongoDB\Driver\Exception\LogicException +Expected Binary of type vector (9) but it is 0 +===DONE===