Skip to content

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

Closed
wants to merge 3 commits into from

Conversation

kocsismate
Copy link
Member

No description provided.

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.");
Copy link
Member

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.

Copy link
Member

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).

Copy link
Member Author

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.

@@ -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");
Copy link
Member

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?

Copy link
Member Author

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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a RETURN_THROWS().

@@ -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");
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:/ Both fixed now!

@php-pulls php-pulls closed this in f068fbc Aug 25, 2020
@kocsismate kocsismate deleted the xmlreader-warning branch August 25, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants