Skip to content

Improve some ValueError messages #5340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static PHP_FUNCTION(bzread)
php_stream_from_zval(stream, bz);

if (len < 0) {
zend_value_error("Length cannot be negative");
zend_argument_value_error(2, "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down Expand Up @@ -367,7 +367,7 @@ static PHP_FUNCTION(bzopen)
}

if (mode_len != 1 || (mode[0] != 'r' && mode[0] != 'w')) {
zend_value_error("'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
zend_argument_value_error(2, "must be a valid mode. Only 'w' and 'r' are supported");
RETURN_THROWS();
}

Expand Down
6 changes: 3 additions & 3 deletions ext/bz2/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ var_dump(bzopen($fp, "r"));

?>
--EXPECTF--
'' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported

Warning: bzopen(): Filename cannot be empty in %s on line %d
bool(false)

Warning: bzopen(): Filename cannot be empty in %s on line %d
bool(false)
'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported

Warning: bzopen(no_such_file): Failed to open stream: No such file or directory in %s on line %d
bool(false)
Expand Down
2 changes: 1 addition & 1 deletion ext/bz2/tests/003-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var_dump(bzread($fd, 100000));
?>
--EXPECT--
string(0) ""
Length cannot be negative
bzread(): Argument #2 ($length) must be greater than or equal to 0
string(1) "R"
string(2) "is"
string(251) "ing up from the heart of the desert
Expand Down
2 changes: 1 addition & 1 deletion ext/bz2/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var_dump(bzread($fd, 100000));
?>
--EXPECT--
string(0) ""
Length cannot be negative
bzread(): Argument #2 ($length) must be greater than or equal to 0
string(1) "R"
string(2) "is"
string(251) "ing up from the heart of the desert
Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/cal_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ PHP_FUNCTION(unixtojd)
if (!ts) {
ts = time(NULL);
} else if (ts < 0) {
zend_value_error("Timestamp must not be negative");
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}

Expand Down
8 changes: 4 additions & 4 deletions ext/calendar/calendar.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ PHP_FUNCTION(cal_info)


if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
zend_argument_value_error(1, "must be a valid calendar ID");
RETURN_THROWS();
}

Expand All @@ -239,7 +239,7 @@ PHP_FUNCTION(cal_days_in_month)
}

if (cal < 0 || cal >= CAL_NUM_CALS) {
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
zend_argument_value_error(1, "must be a valid calendar ID");
RETURN_THROWS();
}

Expand Down Expand Up @@ -285,7 +285,7 @@ PHP_FUNCTION(cal_to_jd)
}

if (cal < 0 || cal >= CAL_NUM_CALS) {
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
zend_argument_value_error(1, "must be a valid calendar ID");
RETURN_THROWS();
}

Expand All @@ -306,7 +306,7 @@ PHP_FUNCTION(cal_from_jd)
}

if (cal < 0 || cal >= CAL_NUM_CALS) {
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
zend_argument_value_error(2, "must be a valid calendar ID");
RETURN_THROWS();
}
calendar = &cal_conversion_table[cal];
Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/easter.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
}

if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */
zend_value_error("This function is only valid for years between 1970 and 2037 inclusive");
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_days_in_month_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ try{
}
?>
--EXPECT--
Invalid calendar ID: -1
cal_days_in_month(): Argument #1 ($calendar) must be a valid calendar ID
Invalid date
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_from_jd_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ try {
}
?>
--EXPECT--
Invalid calendar ID: -1
cal_from_jd(): Argument #2 ($calendar) must be a valid calendar ID
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_info.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ Array
[calname] => Julian
[calsymbol] => CAL_JULIAN
)
Invalid calendar ID: 99999
cal_info(): Argument #1 ($calendar) must be a valid calendar ID
2 changes: 1 addition & 1 deletion ext/calendar/tests/cal_to_jd_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ try {
}
?>
--EXPECT--
Invalid calendar ID: -1
cal_to_jd(): Argument #1 ($calendar) must be a valid calendar ID
2 changes: 1 addition & 1 deletion ext/calendar/tests/easter_date.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ try {
2000-04-23
2001-04-15
2002-03-31
This function is only valid for years between 1970 and 2037 inclusive
easter_date(): Argument #1 ($year) must be between 1970 and 2037 (inclusive)
2 changes: 1 addition & 1 deletion ext/calendar/tests/unixtojd_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var_dump(unixtojd(null)) . PHP_EOL;
var_dump(unixtojd(time())) . PHP_EOL;
?>
--EXPECTF--
Timestamp must not be negative
unixtojd(): Argument #1 ($timestamp) must be greater than or equal to 0
int(%d)
int(%d)
int(%d)
Loading