WPIntell

Source evidence

Sentry combo with is_wp_error

Sentry for WordPress · support · 2022-11-07T09:17:00+00:00

mixedsentiment
mediumseverity
0.72relevance
3replies
Evidence linked to opportunitycommercial context

Proof Health

Open evidence

Commercial opportunities need traceable source links before they are treated as build-worthy.

4 / 25 rows with source links

16.0% of this page's analysis has direct source links.

0 build-decision rows missing links

0 rows here require auditable proof before promotion.

21 rows with no attached evidence

0 rows have source counts but still need direct links.

Conversation

support
anatoli resolved
I’d like to use Sentry to trap everything going in my check like: if(is_wp_error) { …. } I’ve searched in the read.me file but did’nt understood how to do that. Someone can help me? The best place to look is here: https://github.com/stayallive/wp-sentry#capturing-handled-exceptions . However this assumes you have an exception which you don’t, you have a WP_Error object. So you could do something like this instead: if (is_wp_error($result)) { if (function_exists('wp_sentry_safe')) { wp_sentry_safe(function (\Sentry\State\HubInterface $client) use ($result) { $client->withScope(function (\Sentry\State\Scope $scope) use ($client, $result) { $scope->setExtra('messages', $result-> get_error_messages()); $client->captureMessage('CHANGEME: Error while doing...'); }); }); } } Let me know if that helps! Hi Alex, thanks for reply. Your snippet works! Thanks a lot, meanwhile i was trying with this try { myMethodThatCanThrowAnException(); } catch ( \Exception $e ) { // We are using wp_sentry_safe to make sure this code runs even if the Sentry plugin is disabled if ( function_exists( 'wp_sentry_safe' ) ) { wp_sentry_safe( function ( \Sentry\State\HubInterface $client ) use ( $e ) { $client->captureException( $e ); } ); } wp_die( 'There was an error doing this thing you were doing, we have been notified!' ); } and it works as well! Thank you That snippet you shared also works but a WP_Error is not an exception so you need a little different method to capture those. Glad to hear it works, thanks for the update!

Comments

3 shown
stayallive 2022-11-08T08:34:00+00:00

The best place to look is here: https://github.com/stayallive/wp-sentry#capturing-handled-exceptions . However this assumes you have an exception which you don’t, you have a WP_Error object. So you could do something like this instead: if (is_wp_error($result)) { if (function_exists('wp_sentry_safe')) { wp_sentry_safe(function (\Sentry\State\HubInterface $client) use ($result) { $client->withScope(function (\Sentry\State\Scope $scope) use ($client, $result) { $scope->setExtra('messages', $result-> get_error_messages()); $client->captureMessage('CHANGEME: Error while doing...'); }); }); } } Let me know if that helps!

anatoli 2022-11-08T09:01:00+00:00

Hi Alex, thanks for reply. Your snippet works! Thanks a lot, meanwhile i was trying with this try { myMethodThatCanThrowAnException(); } catch ( \Exception $e ) { // We are using wp_sentry_safe to make sure this code runs even if the Sentry plugin is disabled if ( function_exists( 'wp_sentry_safe' ) ) { wp_sentry_safe( function ( \Sentry\State\HubInterface $client ) use ( $e ) { $client->captureException( $e ); } ); } wp_die( 'There was an error doing this thing you were doing, we have been notified!' ); } and it works as well! Thank you

stayallive 2022-11-08T12:06:00+00:00

That snippet you shared also works but a WP_Error is not an exception so you need a little different method to capture those. Glad to hear it works, thanks for the update!