stayallive / wp-sentry

A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.
https://wordpress.org/plugins/wp-sentry-integration/
MIT License
305 stars 48 forks source link

Avoid fatal error if `wp_sentry_options` filter is used but no DSN is set #137

Closed ocean90 closed 2 years ago

ocean90 commented 2 years ago

I'm using the filter to filter out some events before sending them to Sentry. For local development I have not set a DSN and in case of warning I'm getting the following fatal error:

Fatal error: Uncaught Error: Call to a member function getOptions() on null
in /var/www/web/content/plugins/wp-sentry/src/class-wp-sentry-php-tracker.php on line 104

Stack

WP_Sentry_Php_Tracker::on_after_setup_theme()
wp-includes/class-wp-hook.php:307
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:331
WP_Hook::do_action()
wp-includes/plugin.php:476
do_action()
wp-settings.php:576
require_once()
wp-config.php:101
require_once()
wp-load.php:55
require_once()
wp-admin/admin.php:34
require_once()
wp-admin/index.php:10

https://github.com/stayallive/wp-sentry/blob/e697fe5b28ddc014c358e9c0738d95e597e274af/src/class-wp-sentry-php-tracker.php#L102-L106

Of course, I could just disable the plugin but I think it would be nice if such errors are prevented by checking if the client is actually set. Thoughts?

stayallive commented 2 years ago

Jep, that makes perfect sense, that was an oversight on my part, fixed in v5.2.0.

Thanks for reporting!