born05 / craft-sentry

Pushes Craft CMS errors to Sentry.
MIT License
10 stars 11 forks source link

Added `getSentry` method #15

Closed joshuabaker closed 3 years ago

joshuabaker commented 3 years ago

Allows us to use calls like Sentry::$plugin->getSentry()->handleException($exception); without IDEs complaining.

roelvanhintum commented 3 years ago

@joshuabaker thanks! Is Sentry::$plugin->sentry->handleException($exception); a problem with IDE's?

roelvanhintum commented 3 years ago

additionally: To be clear, that method is really meant for craft and it's twig errors. You can always do the following:

use Sentry;

try {
    // Break your code.
} catch (Exception $e) {
    Sentry\captureException($e);
}
joshuabaker commented 3 years ago

It’s mostly able filling in the intellisense and getting rid of the warnings.

https://user-images.githubusercontent.com/160484/104735833-ff206e80-5739-11eb-8fec-9848cfebae79.mov

As it happens, I am using Sentry\captureException($e); now, so I’m happy with whatever you fancy here.

Perhaps a phpDoc block?

/**
 * Class Plugin
 *
 * @package born05\sentry
 * @property-read SentryService $sentry
 */
roelvanhintum commented 3 years ago

@joshuabaker if it is good practice i am happy to merge it (I'm using VS Code, so what do i know). Regardless of that, the capture exception you're currently using is the correct way of handling exceptions. ;)

roelvanhintum commented 3 years ago

Released in 1.0.11