Skip to content

Commit 1efaed7

Browse files
committed
Improve error messages of ext/zlib
1 parent 3a0bdb7 commit 1efaed7

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

ext/zlib/tests/deflate_add_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ try {
2727

2828
?>
2929
--EXPECT--
30-
deflate_add(): supplied resource is not a valid zlib deflate resource
31-
Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH
30+
deflate_add(): Argument #1 ($context) must be of type DeflateContext, resource given
31+
deflate_add(): Argument #3 ($flush_behavior) must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH

ext/zlib/tests/deflate_init_error.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ try {
4141

4242
?>
4343
--EXPECT--
44-
Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE
45-
Compression level (42) must be within -1..9
46-
Compression level (-2) must be within -1..9
47-
Compression memory level (0) must be within 1..9
48-
Compression memory level (10) must be within 1..9
44+
deflate_init(): Argument #1 ($encoding) must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
45+
deflate_init(): "level" option must be between -1 and 9
46+
deflate_init(): "level" option must be between -1 and 9
47+
deflate_init(): "memory" option must be between 1 and 9
48+
deflate_init(): "memory" option must be between 1 and 9

ext/zlib/tests/dictionary_usage.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ var_dump($dictStr_a === $a);
1818
$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => $dict]);
1919
var_dump(inflate_add($r, $a, ZLIB_FINISH));
2020

21-
2221
$r = inflate_init(ZLIB_ENCODING_DEFLATE, ["dictionary" => ["8"] + range("a", "z")]);
2322
var_dump(inflate_add($r, $a, ZLIB_FINISH));
2423

ext/zlib/tests/inflate_add_error.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ try {
2626

2727
?>
2828
--EXPECT--
29-
inflate_add(): supplied resource is not a valid zlib inflate resource
30-
Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH
29+
inflate_add(): Argument #1 ($context) must be of type InflateContext, resource given
30+
inflate_add(): Argument #3 ($flush_mode) must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH

ext/zlib/zlib.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
786786
}
787787
efree(strings);
788788
if (!EG(exception)) {
789-
zend_value_error("Dictionary entries must be non-empty strings");
789+
zend_argument_value_error(2, "must not contain empty strings");
790790
}
791791
return 0;
792792
}
@@ -796,7 +796,7 @@ static zend_bool zlib_create_dictionary_string(HashTable *options, char **dict,
796796
efree(ptr);
797797
} while (--ptr >= strings);
798798
efree(strings);
799-
zend_value_error("Dictionary entries must not contain a NULL-byte");
799+
zend_argument_value_error(2, "must not contain strings with null bytes");
800800
return 0;
801801
}
802802
}
@@ -1077,23 +1077,23 @@ PHP_FUNCTION(deflate_init)
10771077
level = zval_get_long(option_buffer);
10781078
}
10791079
if (level < -1 || level > 9) {
1080-
zend_value_error("Compression level (" ZEND_LONG_FMT ") must be within -1..9", level);
1080+
zend_value_error("deflate_init(): \"level\" option must be between -1 and 9");
10811081
RETURN_THROWS();
10821082
}
10831083

10841084
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) {
10851085
memory = zval_get_long(option_buffer);
10861086
}
10871087
if (memory < 1 || memory > 9) {
1088-
zend_value_error("Compression memory level (" ZEND_LONG_FMT ") must be within 1..9", memory);
1088+
zend_value_error("deflate_init(): \"memory\" option must be between 1 and 9");
10891089
RETURN_THROWS();
10901090
}
10911091

10921092
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
10931093
window = zval_get_long(option_buffer);
10941094
}
10951095
if (window < 8 || window > 15) {
1096-
zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);
1096+
zend_value_error("deflate_init(): \"window\" option must be between 8 and 15");
10971097
RETURN_THROWS();
10981098
}
10991099

@@ -1108,7 +1108,7 @@ PHP_FUNCTION(deflate_init)
11081108
case Z_DEFAULT_STRATEGY:
11091109
break;
11101110
default:
1111-
zend_value_error("Strategy must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY");
1111+
zend_value_error("deflate_init(): \"strategy\" option must be one of ZLIB_FILTERED, ZLIB_HUFFMAN_ONLY, ZLIB_RLE, ZLIB_FIXED or ZLIB_DEFAULT_STRATEGY");
11121112
RETURN_THROWS();
11131113
}
11141114

@@ -1122,7 +1122,7 @@ PHP_FUNCTION(deflate_init)
11221122
case PHP_ZLIB_ENCODING_DEFLATE:
11231123
break;
11241124
default:
1125-
zend_value_error("Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE");
1125+
zend_argument_value_error(1, "must be either ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE");
11261126
RETURN_THROWS();
11271127
}
11281128

@@ -1186,8 +1186,7 @@ PHP_FUNCTION(deflate_add)
11861186
break;
11871187

11881188
default:
1189-
zend_value_error(
1190-
"Flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH");
1189+
zend_argument_value_error(3, "must be one of ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK, or ZLIB_FINISH");
11911190
RETURN_THROWS();
11921191
}
11931192

0 commit comments

Comments
 (0)