Skip to content

Promote mysqli warnings to exceptions #5058

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 1 commit into from

Conversation

kocsismate
Copy link
Member

@kocsismate kocsismate commented Jan 6, 2020

It's a nightmare to adapt the tests... So I'll only continue if we make sure that the warnings in question can be promoted to exceptions. :)

@kocsismate
Copy link
Member Author

@nikic could you tell me if it is really ok to continue?

@nikic
Copy link
Member

nikic commented Jan 8, 2020

Could you please describe under which conditions this error would occur? From what I gathered, it happens if either a) the connection hasn't been opened yet or b) the connection is already closed. I think in principle that would be fine, as it is consistent with us throwing for closed resources.

One thing I'm wondering about in particular is how that interacts with the "Gone away" condition. Would that also result in an exception on the next interaction? That might be fragile.

@kocsismate
Copy link
Member Author

kocsismate commented Jan 8, 2020

It happens if either a) the connection hasn't been opened yet or b) the connection is already closed

You are right, this is my understanding (and experience after working on the tests) as well. Additionally, the resource of prepared statements and results should be open when accessing them in order to avoid throwing an exception.

I think in principle that would be fine

Yep, throwing also makes sense for me, mainly I was unsure about the possible BC impact.

@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch from e6b360b to 49e2a22 Compare January 8, 2020 19:32
@nikic
Copy link
Member

nikic commented Jan 9, 2020

I've looked a bit closer at this now, it should be good to go ahead. I've removed two of the conditions in 55618ff, because they cannot occur in practice.

The Couldn't fetch %s error should be changed to something like %s object is already closed, because that's the only condition under which it should occur.

The invalid object or resource %s could be something like %s object is not fully initialized. What that means depends on the object type, e.g. it's a connection that's not connected, or a statement that's not prepared.

Apart from these suggestions, this change should be in line with our exception guidelines.

@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch from 49e2a22 to cef1e68 Compare January 13, 2020 22:25
@kocsismate
Copy link
Member Author

kocsismate commented Jan 13, 2020

Thank you, Nikita, for having a detailed look! I updated my PR:

@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch 2 times, most recently from 9d983d4 to 46a1153 Compare January 14, 2020 08:34
@kocsismate
Copy link
Member Author

kocsismate commented Jan 14, 2020

OMG, I've just noticed that I echoed the exception itself, not just the message... I should have stopped a little bit earlier yesterday... :)

@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch from 46a1153 to 17dbd35 Compare January 14, 2020 09:02
@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch 4 times, most recently from 16476b4 to d6e3124 Compare January 21, 2020 18:07
@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch 5 times, most recently from 75437a5 to 1c5bfd8 Compare January 25, 2020 10:30
@nikic
Copy link
Member

nikic commented Jan 27, 2020

Could you please split off the last commit into a separate PR? It's really a fix for an independent issue, that just becomes more problematic with exceptions. See https://bugs.php.net/bug.php?id=78666 for bug report.

@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch from 2daf485 to cee9a59 Compare January 28, 2020 20:10
@kocsismate kocsismate force-pushed the mysqli-promote-warnings branch from cee9a59 to 85e13c0 Compare January 28, 2020 21:29
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