Improve error messages of various extensions

Closes GH-5278
This commit is contained in:
Máté Kocsis 2020-03-18 22:44:02 +01:00
parent d7b73de8c9
commit 01b266aac4
No known key found for this signature in database
GPG key ID: FD055E41728BF310
29 changed files with 100 additions and 100 deletions

View file

@ -379,7 +379,7 @@ static PHP_FUNCTION(bzopen)
}
if (CHECK_ZVAL_NULL_PATH(file)) {
zend_type_error("Filename must not contain null bytes");
zend_argument_type_error(1, "must not contain null bytes");
RETURN_THROWS();
}
@ -430,7 +430,7 @@ static PHP_FUNCTION(bzopen)
stream = php_stream_bz2open_from_BZFILE(bz, mode, stream);
} else {
zend_type_error("First parameter has to be string or file-resource");
zend_argument_type_error(1, "must be of type string or file-resource, %s given", zend_zval_type_name(file));
RETURN_THROWS();
}

View file

@ -91,10 +91,10 @@ resource(%d) of type (stream)
resource(%d) of type (stream)
Warning: fopen(bz_open_002.txt): Failed to open stream: Bad file %s in %s on line %d
First parameter has to be string or file-resource
bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
Warning: fopen(bz_open_002.txt): Failed to open stream: Bad file %s in %s on line %d
First parameter has to be string or file-resource
bzopen(): Argument #1 ($file) must be of type string or file-resource, bool given
Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d
bool(false)

View file

@ -7,17 +7,17 @@ bzopen(): throw TypeError if filename contains null bytes
try {
bzopen("file\0", "w");
} catch (\TypeError $e) {
} catch (TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
bzopen("file\0", "r");
} catch (\TypeError $e) {
} catch (TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECT--
Filename must not contain null bytes
Filename must not contain null bytes
bzopen(): Argument #1 ($file) must not contain null bytes
bzopen(): Argument #1 ($file) must not contain null bytes

View file

@ -197,7 +197,7 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
} else {
xmlFree(fragment);
zend_type_error("Invalid argument type must be either DOMNode or string");
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
return NULL;
}
} else if (Z_TYPE(nodes[i]) == IS_STRING) {
@ -213,7 +213,7 @@ xmlNode* dom_zvals_to_fragment(php_libxml_ref_obj *document, xmlNode *contextNod
} else {
xmlFree(fragment);
zend_type_error("Invalid argument type must be either DOMNode or string");
zend_argument_type_error(i + 1, "must be of type DOMNode|string, %s given", zend_zval_type_name(&nodes[i]));
return NULL;
}

View file

@ -15,4 +15,4 @@ try {
echo "OK! {$e->getMessage()}";
}
--EXPECT--
OK! Invalid argument type must be either DOMNode or string
OK! DOMElement::append(): Argument #1 must be of type DOMNode|string, array given

View file

@ -3885,7 +3885,7 @@ PHP_FUNCTION(imageaffine)
src = php_gd_libgdimageptr_from_zval_p(IM);
if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
zend_value_error("Affine array must have six elements");
zend_argument_value_error(2, "must have 6 elements");
RETURN_THROWS();
}
@ -3902,7 +3902,7 @@ PHP_FUNCTION(imageaffine)
affine[i] = zval_get_double(zval_affine_elem);
break;
default:
zend_type_error("Invalid type for element %i", i);
zend_argument_type_error(3, "contains invalid type for element %i", i);
RETURN_THROWS();
}
}
@ -3970,7 +3970,7 @@ PHP_FUNCTION(imageaffinematrixget)
case GD_AFFINE_SCALE: {
double x, y;
if (!options || Z_TYPE_P(options) != IS_ARRAY) {
zend_type_error("Array expected as options when using translate or scale");
zend_argument_type_error(1, "must be of type array when using translate or scale");
RETURN_THROWS();
}
@ -4002,7 +4002,7 @@ PHP_FUNCTION(imageaffinematrixget)
double angle;
if (!options) {
zend_type_error("Number is expected as option when using rotate or shear");
zend_argument_type_error(2, "must be of type int|double when using rotate or shear");
RETURN_THROWS();
}
@ -4019,7 +4019,7 @@ PHP_FUNCTION(imageaffinematrixget)
}
default:
zend_value_error("Invalid type for element " ZEND_LONG_FMT, type);
zend_argument_value_error(1, "must be a valid element type");
RETURN_THROWS();
}
@ -4068,7 +4068,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
m1[i] = zval_get_double(tmp);
break;
default:
zend_type_error("Matrix 1 contains invalid type for element %i", i);
zend_argument_type_error(1, "contains invalid type for element %i", i);
RETURN_THROWS();
}
}
@ -4085,7 +4085,7 @@ PHP_FUNCTION(imageaffinematrixconcat)
m2[i] = zval_get_double(tmp);
break;
default:
zend_type_error("Matrix 2 contains invalid type for element %i", i);
zend_argument_type_error(2, "contains invalid type for element %i", i);
RETURN_THROWS();
}
}
@ -4299,7 +4299,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
close_stream = 0;
} else if (Z_TYPE_P(to_zval) == IS_STRING) {
if (CHECK_ZVAL_NULL_PATH(to_zval)) {
zend_type_error("Invalid 2nd parameter, filename must not contain null bytes");
zend_argument_type_error(2, "must not contain null bytes");
RETURN_THROWS();
}

View file

@ -16,10 +16,10 @@ for($i=0;$i<7;$i++) {
}
?>
--EXPECT--
!! [TypeError] Array expected as options when using translate or scale
!! [TypeError] Array expected as options when using translate or scale
!! [TypeError] Number is expected as option when using rotate or shear
!! [TypeError] Number is expected as option when using rotate or shear
!! [TypeError] Number is expected as option when using rotate or shear
!! [ValueError] Invalid type for element 5
!! [ValueError] Invalid type for element 6
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
!! [TypeError] imageaffinematrixget(): Argument #1 ($type) must be of type array when using translate or scale
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
!! [TypeError] imageaffinematrixget(): Argument #2 ($options) must be of type int|double when using rotate or shear
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type
!! [ValueError] imageaffinematrixget(): Argument #1 ($type) must be a valid element type

View file

@ -15,4 +15,4 @@ try {
}
?>
--EXPECT--
Invalid 2nd parameter, filename must not contain null bytes
imagebmp(): Argument #2 ($to) must not contain null bytes

View file

@ -14,4 +14,4 @@ try {
}
?>
--EXPECT--
Invalid 2nd parameter, filename must not contain null bytes
imagegif(): Argument #2 ($to) must not contain null bytes

View file

@ -18,4 +18,4 @@ try {
}
?>
--EXPECT--
Invalid 2nd parameter, filename must not contain null bytes
imagejpeg(): Argument #2 ($to) must not contain null bytes

View file

@ -18,4 +18,4 @@ try {
}
?>
--EXPECTF--
Invalid 2nd parameter, filename must not contain null bytes
imagepng(): Argument #2 ($to) must not contain null bytes

View file

@ -18,4 +18,4 @@ try {
}
?>
--EXPECT--
Invalid 2nd parameter, filename must not contain null bytes
imagewbmp(): Argument #2 ($to) must not contain null bytes

View file

@ -18,4 +18,4 @@ try {
}
?>
--EXPECT--
Invalid 2nd parameter, filename must not contain null bytes
imagewebp(): Argument #2 ($to) must not contain null bytes

View file

@ -1272,7 +1272,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
* single value is an array. Also we'd have to make that one
* argument passed by reference.
*/
zend_throw_exception(zend_ce_exception, "Parameter ctor_params must be an array", 0);
zend_argument_error(zend_ce_exception, 3, "must be of type array, %s given", zend_zval_type_name(ctor_params));
RETURN_THROWS();
}
}

View file

@ -6640,7 +6640,7 @@ PHP_OPENSSL_API zend_string* php_openssl_random_pseudo_bytes(zend_long buffer_le
|| ZEND_LONG_INT_OVFL(buffer_length)
#endif
) {
zend_throw_exception(zend_ce_error, "Length must be greater than 0", 0);
zend_argument_error(NULL, 1, "must be greater than 0");
return NULL;
}
buffer = zend_string_alloc(buffer_length, 0);

View file

@ -11,4 +11,4 @@ try {
}
?>
--EXPECT--
Length must be greater than 0
openssl_random_pseudo_bytes(): Argument #1 ($length) must be greater than 0

View file

@ -2303,7 +2303,7 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, int is_filter)
}
} else {
if (Z_TYPE_P(regex) != IS_ARRAY) {
zend_type_error("Parameter mismatch, pattern is a string while replacement is an array");
zend_argument_type_error(1, "must be of type array when argument #2 ($replace) is an array, %s given", zend_zval_type_name(regex));
RETURN_THROWS();
}
}

View file

@ -17,7 +17,7 @@ try {
var_dump(preg_replace_callback("/(ab)(cd)(e)/", array(new foo(), "cb"), 'abcde'));
?>
--EXPECT--
Parameter mismatch, pattern is a string while replacement is an array
preg_replace(): Argument #1 ($regex) must be of type array when argument #2 ($replace) is an array, string given
array(4) {
[0]=>
string(5) "abcde"

View file

@ -36,6 +36,6 @@ Arg value is: this is a string
string(64) "this is a stringthis is a stringthis is a stringthis is a string"
Arg value is: Array
Parameter mismatch, pattern is a string while replacement is an array
preg_replace(): Argument #1 ($regex) must be of type array when argument #2 ($replace) is an array, string given
Object of class stdClass could not be converted to string
Done

View file

@ -225,7 +225,7 @@ static PHP_METHOD(PDO, dbh_constructor)
snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source);
if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name");
zend_argument_error(php_pdo_get_exception(), 1, "must be a valid data source name");
RETURN_THROWS();
}
@ -242,12 +242,12 @@ static PHP_METHOD(PDO, dbh_constructor)
/* the specified URI holds connection details */
data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn));
if (!data_source) {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI");
zend_argument_error(php_pdo_get_exception(), 1, "must be a valid data source URI");
RETURN_THROWS();
}
colon = strchr(data_source, ':');
if (!colon) {
zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)");
zend_argument_error(php_pdo_get_exception(), 1, "must be a valid data source name (via URI)");
RETURN_THROWS();
}
}

View file

@ -293,11 +293,11 @@ MySQLPDOTest::skip();
print "done!";
?>
--EXPECTF--
[002] invalid data source name, [n/a] n/a
[003] invalid data source name, [n/a] n/a
[004] invalid data source name, [n/a] n/a
[005] invalid data source name, [n/a] n/a
[006] invalid data source name, [n/a] n/a
[002] PDO::__construct(): Argument #1 ($dsn) must be a valid data source name, [n/a] n/a
[003] PDO::__construct(): Argument #1 ($dsn) must be a valid data source name, [n/a] n/a
[004] PDO::__construct(): Argument #1 ($dsn) must be a valid data source name, [n/a] n/a
[005] PDO::__construct(): Argument #1 ($dsn) must be a valid data source name, [n/a] n/a
[006] PDO::__construct(): Argument #1 ($dsn) must be a valid data source name, [n/a] n/a
[007] could not find driver, [n/a] n/a
[009] SQLSTATE[%s] [1045] Access denied for user 'dont%s'@'%s' (using password: YES), [n/a] n/a
[017] DSN=%s, SQLSTATE[%s] [%d] %s

View file

@ -2282,15 +2282,15 @@ SXE_METHOD(__construct)
}
if (ZEND_SIZE_T_INT_OVFL(data_len)) {
zend_throw_exception(zend_ce_exception, "Data is too long", 0);
zend_argument_error(zend_ce_exception, 1, "is too long");
RETURN_THROWS();
}
if (ZEND_SIZE_T_INT_OVFL(ns_len)) {
zend_throw_exception(zend_ce_exception, "Namespace is too long", 0);
zend_argument_error(zend_ce_exception, 4, "is too long");
RETURN_THROWS();
}
if (ZEND_LONG_EXCEEDS_INT(options)) {
zend_throw_exception(zend_ce_exception, "Invalid options", 0);
zend_argument_error(zend_ce_exception, 2, "is invalid");
RETURN_THROWS();
}

View file

@ -10,7 +10,7 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platforms only");
$xml=new SimpleXMLElement(0,9000000000);var_dump($xml->getDocNamespaces())?>
?>
--EXPECTF--
Fatal error: Uncaught Exception: Invalid options in %sbug74950.php:%d
Fatal error: Uncaught Exception: SimpleXMLElement::__construct(): Argument #2 ($options) is invalid in %sbug74950.php:%d
Stack trace:
#0 %sbug74950.php(%d): SimpleXMLElement->__construct('0', 9000000000)
#1 {main}

View file

@ -1540,7 +1540,7 @@ PHP_METHOD(snmp, __construct)
case SNMP_VERSION_3:
break;
default:
zend_throw_exception(zend_ce_exception, "Unknown SNMP protocol version", 0);
zend_argument_value_error(zend_ce_exception, 1, "must be a valid SNMP protocol version");
RETURN_THROWS();
}

View file

@ -72,7 +72,7 @@ var_dump($session->max_oids);
SNMP::__construct() expects at least 3 parameters, 2 given
SNMP::__construct(): Argument #4 must be of type int, string given
SNMP::__construct(): Argument #5 must be of type int, string given
Unknown SNMP protocol version
SNMP::__construct(): Argument #1 ($version) must be a valid SNMP protocol version
Exception handling
Warning: SNMP::get(): Invalid object identifier: .1.3.6.1.2.1.1.1..0 in %s on line %d

View file

@ -93,7 +93,7 @@ PHP_FUNCTION(class_parents)
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_type_error("Object or string expected");
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(obj));
RETURN_THROWS();
}
@ -126,7 +126,7 @@ PHP_FUNCTION(class_implements)
RETURN_THROWS();
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_type_error("Object or string expected");
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(obj));
RETURN_THROWS();
}
@ -155,7 +155,7 @@ PHP_FUNCTION(class_uses)
RETURN_THROWS();
}
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
zend_type_error("Object or string expected");
zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(obj));
RETURN_THROWS();
}

View file

@ -119,61 +119,61 @@ fclose($res);
*** Testing class_implements() : variation ***
--int 0--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, int given
--int 1--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, int given
--int 12345--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, int given
--int -12345--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, int given
--float 10.5--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, float given
--float -10.5--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, float given
--float 12.3456789000e10--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, float given
--float -12.3456789000e10--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, float given
--float .5--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, float given
--empty array--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, array given
--int indexed array--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, array given
--associative array--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, array given
--nested arrays--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, array given
--uppercase NULL--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, null given
--lowercase null--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, null given
--lowercase true--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, bool given
--lowercase false--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, bool given
--uppercase TRUE--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, bool given
--uppercase FALSE--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, bool given
--empty string DQ--
Error: 2 - class_implements(): Class does not exist and could not be loaded, %s(%d)
@ -194,10 +194,10 @@ array(0) {
}
--undefined var--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, null given
--unset var--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, null given
--resource--
Object or string expected
class_implements(): Argument #1 ($what) must be of type object|string, resource given

View file

@ -119,61 +119,61 @@ fclose($res);
*** Testing class_uses() : variation ***
--int 0--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, int given
--int 1--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, int given
--int 12345--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, int given
--int -12345--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, int given
--float 10.5--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, float given
--float -10.5--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, float given
--float 12.3456789000e10--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, float given
--float -12.3456789000e10--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, float given
--float .5--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, float given
--empty array--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, array given
--int indexed array--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, array given
--associative array--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, array given
--nested arrays--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, array given
--uppercase NULL--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, null given
--lowercase null--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, null given
--lowercase true--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, bool given
--lowercase false--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, bool given
--uppercase TRUE--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, bool given
--uppercase FALSE--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, bool given
--empty string DQ--
Error: 2 - class_uses(): Class does not exist and could not be loaded, %s(%d)
@ -192,10 +192,10 @@ array(0) {
}
--undefined var--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, null given
--unset var--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, null given
--resource--
Object or string expected
class_uses(): Argument #1 ($what) must be of type object|string, resource given

View file

@ -819,7 +819,7 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
} break;
default:
zend_type_error("Dictionary must be of type zero-terminated string or array, got %s", zend_get_type_by_const(Z_TYPE_P(option_buffer)));
zend_argument_type_error(2, "must be of type zero-terminated string or array, %s given", zend_get_type_by_const(Z_TYPE_P(option_buffer)));
return 0;
}
}