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

Check if there is a hint exception defined #3

Conversation

rbnmulder
Copy link
Member

No description provided.

@rbnmulder rbnmulder requested a review from indykoning June 30, 2023 08:23
@rbnmulder rbnmulder linked an issue Jun 30, 2023 that may be closed by this pull request
$messages = $this->json->unserialize($this->scopeConfig->getValue('sentry/event_filtering/messages'));
foreach ($messages as $message) {
if (str_contains($hintMessage, $message['message'])) {
$observer->getEvent()->getSentryEvent()->unsEvent();
Copy link
Member

Choose a reason for hiding this comment

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

Once we've unset the event there is no reason to keep looping, correct?
It may be a good idea to break out of the loop in that case 🙂

Suggested change
$observer->getEvent()->getSentryEvent()->unsEvent();
$observer->getEvent()->getSentryEvent()->unsEvent();
break;

Comment on lines 33 to 38
if ($hint?->exception !== null) {
$hintMessage = $hint->exception->getMessage();
if ($hint->exception instanceof LocalizedException) {
$hintMessage = $hint->exception->getRawMessage();
$event->setMessage($hintMessage);
}
Copy link
Member

Choose a reason for hiding this comment

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

Aren't we able to get the message some other way when we do not have the exception, like getting it from the Event itself?
Then at least we will be able to continue to filter out events even without hint.

Suggested change
if ($hint?->exception !== null) {
$hintMessage = $hint->exception->getMessage();
if ($hint->exception instanceof LocalizedException) {
$hintMessage = $hint->exception->getRawMessage();
$event->setMessage($hintMessage);
}
$hintMessage = $hint?->exception?->getMessage() ?? $event->getMessage();
if ($hint?->exception instanceof LocalizedException) {
$hintMessage = $hint->exception->getRawMessage() ;
$event->setMessage($hintMessage);
}

Otherwise i would suggest flipping the logic of the if and returning early to reduct the depth of if/else

Suggested change
if ($hint?->exception !== null) {
$hintMessage = $hint->exception->getMessage();
if ($hint->exception instanceof LocalizedException) {
$hintMessage = $hint->exception->getRawMessage();
$event->setMessage($hintMessage);
}
if ($hint?->exception === null) {
return
}
$hintMessage = $hint->exception->getMessage();
if ($hint->exception instanceof LocalizedException) {
$hintMessage = $hint->exception->getRawMessage();
$event->setMessage($hintMessage);
}

@rbnmulder rbnmulder requested a review from indykoning June 30, 2023 11:30
@indykoning indykoning merged commit f764225 into justbetter:master Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I'm getting a PHP warming message when the Hint exception is null
2 participants