Skip to content
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

Uncaught assertions causing fatal errors on PHP 8+ #706

Conversation

nmolham-godaddy
Copy link
Contributor

@nmolham-godaddy nmolham-godaddy commented Aug 29, 2024

Summary

Prevent assert debug statements from throwing fatal errors.

Story: MWC-11044

Release: #705

Details

Added a SV_WC_Plugin::assert method to perform the assertion and log the failed ones without causing fatal errors.

QA

Before merge

@nmolham-godaddy nmolham-godaddy changed the base branch from release/5.14.0 to chore/setup-autoloading August 29, 2024 08:02
@nmolham-godaddy nmolham-godaddy marked this pull request as draft August 29, 2024 08:37
@nmolham-godaddy
Copy link
Contributor Author

@agibson-godaddy you are much better than me in Github actions, I have been trying for a while getting this working but I kept failing. The idea is configure the ini setting zend.assertions=1 for the new test to pass.
On my local env, I have that configured and works as expected, but I am having a very difficult time making it work online.

Can you take a look?

Copy link
Contributor

@agibson-godaddy agibson-godaddy left a comment

Choose a reason for hiding this comment

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

Code wise this LGTM! Nice work.

I do wonder if separately we need to re-evaluate the usefulness of these assertions? For example:

public function get_gateway_class_name( $gateway_id ) {

	$this->assert( isset( $this->gateways[ $gateway_id ]['gateway_class_name'] ) );

	return $this->gateways[ $gateway_id ]['gateway_class_name'];
}

That's meant to be validating the gateway class name isset. But if it's not set then we'll actually still end up here:

return $this->gateways[ $gateway_id ]['gateway_class_name'];

and then it will trigger a PHP notice if that index doesn't exist. Point being: even if the assertion fails, we're still continuing with our code anyway, which seems counter-intuitive.

To be clear: I don't think this is a problem with your changes, which is why I'm still approving this. It's a more broad comment on our use of assert() in general. Maybe some of them make sense, but the one I pasted above is an example that just seems a bit odd.

Base automatically changed from chore/setup-autoloading to release/5.14.0 August 30, 2024 02:35
@nmolham-godaddy nmolham-godaddy marked this pull request as ready for review August 30, 2024 02:36
@nmolham-godaddy
Copy link
Contributor Author

Thanks @agibson-godaddy for solving that ini config problem, impressive work as usual.

Regarding your comment about the assert usage: Now as I think of think based on your comment, I agree that some of them are counter-intuitive indeed 🤔

I assume the main purpose of these assertions are making sure the necessary data structure for the gateways to function are defined in the implementation of these classes.

I will open another PR to clean them up and validate each one use-case, but for now, I will merge this PR to release the new framework version 🥳

@nmolham-godaddy nmolham-godaddy merged commit 0c24c03 into release/5.14.0 Aug 30, 2024
5 checks passed
@nmolham-godaddy nmolham-godaddy deleted the mwc-11044/uncaught-assertions-causing-fatal-errors branch August 30, 2024 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants