-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[DBAL-2954] Removed error suppression in IBM DB2 Statement #2955
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
Looking into the source, it looks like there is more different errors, not just conversion related but also binding-related errors and execution failure errors. Aren't these the reason for |
One solution could be: keep |
Most probably that's the case.
IMO, not all errors should be promoted to exceptions. If an error didn't cause the method to return In a general case, a single call to |
With this solution, an internal fatal error will cause silent script termination. Happy debugging. |
Right, because catchable fatal isn't actually catchable by |
@Majkl578 so you're suggesting something like this? set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) {
throw new DB2Exception($errstr);
});
try {
$retval = db2_execute($this->_stmt, $params);
} finally {
restore_error_handler();
} It is better than error suppression but it may introduce false positives in the cases which did trigger errors but didn't cause the I didn't explore the extension source code but something makes me think that all possible notices are not run-time but logical (revealing bugs in the userland code). Having them also displayed as native PHP notices doesn't look like a big deal to me. |
/cc @asgrim can you maybe read through this? You got much more DB2 |
I think this is less a discussion about DB2 itself, and really it's "how should errors from the driver be propagated"... PHP 7 now having Though, playing devil's advocate, thinking back to when we first started implementing the DB2-based project, I remember the That said, especially if DBAL still supports PHP 5.x, I think @Majkl578's solution of setting an error handler would work universally and nicely (convert everything to exception: if it's a notice that the consumer doesn't care about, that can be handled that in the consumer code). |
@asgrim this is for PHP 7.1+ only though. Unless security issues pop up in |
In that case, would it be so bad to remove the |
Not quite, it can still throw a fatal that is not catchable by
In this case, we'd have to store errors in set_error_handler and throw them conditionally. I'm not a fan of either of these solutions, but I guess it's about what's less evil in the end. <?php
$errors = [];
set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) use (&$errors) {
$errors[] = $errstr;
});
try {
$retval = db2_execute($this->_stmt, $params);
if ($retval === false && count($errors) !== 0) {
throw DB2Exception::fromMultiple($errors);
}
} finally {
restore_error_handler();
} Don't like this solution either. :/ |
And it doesn't solve the original problem. The notice in the example will still be suppressed since it doesn't cause A complete solution would contain the |
@Netmosfera job for you? |
if you are not throwing the exception, you are collecting the errors for... what? EDIT: nvm, I understand now. |
function retrigger_error(string $message, int $type){
$conversions = [
E_ERROR => E_USER_ERROR,
E_WARNING => E_USER_WARNING,
E_NOTICE => E_USER_NOTICE,
E_DEPRECATED => E_USER_DEPRECATED,
];
foreach($conversions as $from => $to){
if($type & $from){
$type = $type & ~$from;
$type = $type | $to;
}
}
trigger_error($message, $type);
} EDIT: I think that will work for most cases except when there is an EDIT 2: since it's not actually a mask, the code would be this: function retrigger_error(string $message, int $type){
switch($type){
case E_ERROR: $type = E_USER_ERROR; break;
case E_WARNING: $type = E_USER_WARNING; break;
case E_NOTICE: $type = E_USER_NOTICE; break;
case E_DEPRECATED: $type = E_USER_DEPRECATED; break;
}
trigger_error($message, $type);
} |
@Majkl578 @Netmosfera with the approach of a custom error handler, we will tremendously increase the code complexity in order to overcome the bad design of the Are you sure you want to proceed this route? I still believe just remove the suppression is fine. The worst thing which can happen is in some (which exactly?) cases, the same error may be reported as error and exception. Unless it's a runtime error, I believe, it's perfectly fine. |
Personally I don't, I would just remove the error suppression, let the notices be, and just check for the return value. |
There is one more issue with just removing the suppression: BC. Because if the function suddenly starts throwing notices/warnings, strict/debug tools will immediately catch them and convert into exception. And since original code depended on DB2Exception but now receives i.e. ErrorException, that could break code. |
why are you converting notices to ErrorException? |
For correctness' sake and in case you decide to go with that route, I've just been informed that |
Because even notice means bug. See for example https://github.com/nette/tracy#visualization-of-errors-and-exceptions. |
programming bugs though |
This is fine because they will indicate bugs in the userland code. Otherwise, we need an example of an error which doesn't produce
It will receive
You mean we'll be catching |
I'm lost again :-P |
So, is there a strong disagreement with the current implementation? I still believe that a simple solution which sometimes will report the same error twice is better than a complex one or the one which will suppress (essentially, lose) some errors. |
@Ocramius do you still have any concerns/reservations? |
No, I'm fine with letting the brokenness of the DB2 adapter exposed. Silencing was a much worse solution indeed. |
Note: this only targets |
Fixes #2954.