-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Promote warnings to exceptions in ext/xmlreader #6021
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
Conversation
ext/xmlreader/php_xmlreader.c
Outdated
php_error_docref(NULL, E_WARNING, "Unable to set schema. This must be set prior to reading or schema contains errors."); | ||
|
||
RETURN_FALSE; | ||
zend_throw_error(NULL, "Unable to set schema. This must be set prior to reading or schema contains errors."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"schema contains errors" doesn't sound like a promotable condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be split into the error condition for !intern || !intern->ptr
(can throw) and the one for retval != 0 (cannot throw).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the recommendation, I managed to separate them, and I added test coverage for both the warning and the exception.
ext/xmlreader/php_xmlreader.c
Outdated
@@ -781,8 +790,7 @@ PHP_METHOD(XMLReader, read) | |||
} | |||
} | |||
|
|||
php_error_docref(NULL, E_WARNING, "Load Data before trying to read"); | |||
RETURN_FALSE; | |||
zend_throw_error(NULL, "Data must be loaded before reading"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: Rewrite this as early return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense for me!
RETURN_BOOL(retval); | ||
} | ||
if (intern == NULL || intern->ptr == NULL) { | ||
zend_throw_error(NULL, "Data must be loaded before reading"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a RETURN_THROWS().
ext/xmlreader/php_xmlreader.c
Outdated
@@ -506,15 +506,16 @@ static void php_xmlreader_set_relaxng_schema(INTERNAL_FUNCTION_PARAMETERS, int t | |||
intern->schema = schema; | |||
|
|||
RETURN_TRUE; | |||
} else { | |||
zend_throw_error(NULL, "Schema contains errors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be a warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:/ Both fixed now!
No description provided.