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

REF Update CiviCRM default PEAR Error handling to be exception rather… #19323

Merged

Conversation

seamuslee001
Copy link
Contributor

… than just PEAR_Error object and remove useException overirdes as no longer needed and patch necessary places to handle with Exceptions coming back

Overview

This is a substantial change but an important one and I think we can do this now. This changes the default error handling of PEAR Errors to be rather than just processing the PEAR_Error object that we now convert it into throwing an Exception. This has always been the case for our unit tests but not in general run time. I took a look by greping for isError and also PEAR_Error and didn't see many instances where we were directly relying on PEAR_Error and in those instances I have changed to use try catch versions

Before

During normal run time PEAR_Error emitted

After

Exception Emitted containing the PEAR_Error object during normal runtime

Technical Details

Note this doesn't touch a number of places in the MailingJob / Mailing Code as those explicitly set the temporary Error scope to be ignoreException so shouldn't be impacted by this change

ping @totten @eileenmcnaughton @mattwire @demeritcowboy

… than just PEAR_Error object and remove useException overirdes as no longer needed and patch necessary places to handle with Exceptions coming back
@civibot
Copy link

civibot bot commented Jan 5, 2021

(Standard links)

@civibot civibot bot added the master label Jan 5, 2021
@seamuslee001
Copy link
Contributor Author

One advantage of this also is that it means that our unit tests error handling will now be the same as general runtime

@eileenmcnaughton
Copy link
Contributor

If jenkins is OK with this I'd be keen to merge once the rc is cut. I think this is definitely where we want to wind up on this

@@ -1398,9 +1398,6 @@ public static function sendSMSMessage(

$providerObj = CRM_SMS_Provider::singleton(['provider_id' => $smsProviderParams['provider_id']]);
$sendResult = $providerObj->send($recipient, $smsProviderParams, $tokenText, NULL, $sourceContactID);
if (PEAR::isError($sendResult)) {
throw new CRM_Core_Exception($sendResult->getMessage());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess I can test this but I think most SMS extensions specifically call PEAR::raiseError, so does that internally now get converted automatically to an exception or would that still be a pear error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would get converted because this is changing the PEAR error callback https://github.com/civicrm/civicrm-core/pull/19323/files#diff-dc1c0506257784ef60b0b3f296a5e64c633c0a19d47dbd87885eb21852836fd6R89 to be this function instead of this one

Copy link
Contributor

Choose a reason for hiding this comment

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

So no more familiar yellow screen? 😢 I'll get over it...

Tested and yes it errors with a PEAR_Exception now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will because if Exception isn't handled it should wind up here https://github.com/civicrm/civicrm-core/blob/master/CRM/Core/Error.php#L438

Copy link
Contributor

@demeritcowboy demeritcowboy Jan 5, 2021

Choose a reason for hiding this comment

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

Oh I see, you just have to scroll down to see it. 😀

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton now that we have RC should we merge this?

@eileenmcnaughton
Copy link
Contributor

OK let's do it. I re-read the code and I think it should all be OK & we get a nice long lead time

@eileenmcnaughton eileenmcnaughton merged commit 01924a0 into civicrm:master Jan 11, 2021
@demeritcowboy
Copy link
Contributor

One thing I'm noticing about this is that api calls fail more silently because they catch the PEAR_Exception. It still logs it, but there might not be any visual clues that something went wrong. An example is a db call during an api call that fails with No Such Field.

The main problem though is that in unit test runs such a thing now succeeds, whereas before it error'd.

Hmm.

@eileenmcnaughton eileenmcnaughton deleted the default_handler_exception branch February 4, 2021 21:13
@eileenmcnaughton
Copy link
Contributor

@demeritcowboy can we replicate that? if so we should dig

@demeritcowboy
Copy link
Contributor

Ok have put up #19532. I'm sure I could think of a better one to use for real, but should work for demo purposes.

colemanw added a commit to colemanw/civicrm-core that referenced this pull request Nov 15, 2022
Following up on civicrm#19323 this converts APIv3 in Smarty and Ajax to use exceptions instead
of overriding the PEAR exception handler. Now that PEAR throws exceptions there is
no need to do so and it was interfering with try/catch handlers within the api call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants