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

Unwrap HandlerFailedException for sync Messenger messages too #475

Closed
wants to merge 8 commits into from

Conversation

Jean85
Copy link
Collaborator

@Jean85 Jean85 commented Apr 1, 2021

Will fix #469

@Jean85 Jean85 added this to the 4.0 milestone Apr 1, 2021
@Jean85 Jean85 self-assigned this Apr 1, 2021
@Jean85 Jean85 marked this pull request as ready for review April 1, 2021 12:50
@Jean85 Jean85 requested a review from ste93cry April 1, 2021 12:50
Copy link
Contributor

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

assuming (needs to be checked by maintainers) that HandlerFailedException can be un-wrapped by default within the context of ErrorListener#handleExceptionEvent(), I'm totally for this patch 👍

@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 1, 2021

IMO it should, because it can also contain multiple exceptions, due to multiple handlers for the same message, failing together.

Copy link
Collaborator

@ste93cry ste93cry left a comment

Choose a reason for hiding this comment

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

Build is broken 😬

tests/End2End/App/Controller/MessengerController.php Outdated Show resolved Hide resolved
tests/End2End/App/Messenger/IgnorableException.php Outdated Show resolved Hide resolved
tests/End2End/App/Messenger/SyncMessage.php Outdated Show resolved Hide resolved
tests/End2End/App/Messenger/SyncMessageHandler.php Outdated Show resolved Hide resolved
@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 2, 2021

CI failure seems triggered by symfony/symfony#40677

If we cannot fix it, we can (temporarily?) switch to pcov for coverage collection?

@Ocramius
Copy link
Contributor

Ocramius commented Apr 2, 2021

@Jean85 IMO using pcov is more reliable, if this stuff is only used for coverage.

@Ocramius
Copy link
Contributor

Ocramius commented Apr 2, 2021

There was 1 failure:

1) Sentry\SentryBundle\Tests\End2End\End2EndTest::testGetFatal
Wrong number of events sent: 
7222250960a0483195f2e5ea66896f9e: Error: Class Serializable@anonymous contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Serializable::serialize, Serializable::unserialize)
###
3284d7459e2d4725a34edd8ee85ce6c8: Error: Class Serializable@anonymous contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Serializable::serialize, Serializable::unserialize)
###

Failed asserting that actual size 2 matches expected size 1.

/home/runner/work/sentry-symfony/sentry-symfony/tests/End2End/End2EndTest.php:258
/home/runner/work/sentry-symfony/sentry-symfony/tests/End2End/End2EndTest.php:157

I wonder if that's because the messenger encounters the fatal error twice? Then the exception would indeed be captured twice, with the current change.

@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 2, 2021

Why would encounter it twice?

Also, tests do NOT fail locally, there's definitely something wonky here..

@Ocramius
Copy link
Contributor

Ocramius commented Apr 2, 2021

The code around the assertions looks completely wonky:

try {
$client->insulate(true);
$client->request('GET', '/fatal');
$response = $client->getResponse();
$this->assertInstanceOf(Response::class, $response);
$this->assertSame(500, $response->getStatusCode());
$this->assertStringNotContainsString('not happen', $response->getContent() ?: '');
} catch (\RuntimeException $exception) {
$this->assertStringContainsStringIgnoringCase('error', $exception->getMessage());
$this->assertStringContainsStringIgnoringCase('contains 2 abstract methods', $exception->getMessage());
$this->assertStringContainsStringIgnoringCase('MainController.php', $exception->getMessage());
$this->assertStringContainsStringIgnoringCase('eval()\'d code on line', $exception->getMessage());
}

The } catch { block should not exist there, should it?

@Jean85
Copy link
Collaborator Author

Jean85 commented Apr 2, 2021

IIRC that was done in #322 due to the fact that with different Symfony version you would get different behaviours..

Let's see what happens if I revert that.

[EDIT] The reason is a bit more nuanced:

  • that test triggers a fatal through evaling a string which contains an anonymous empty class extending \Serializable:
    $foo = eval("return new class() implements \Serializable {};");
  • hence $client->insulate(true), which runs the request inside a process to avoid bringing down the whole test with it
  • code throws at $client->request(..), so the test continues flowing from inside the catch block
  • code after $client->request(..) is just to capture behaviour if the app under test is behaving badly: controller has a fixed response if it doesn't blow up as expected:
    return new Response('This response should not happen: ' . json_encode($foo));

@ste93cry ste93cry modified the milestones: 4.0, 4.1 Apr 19, 2021
@Jean85 Jean85 force-pushed the fix-messenger-sync-errors branch from 067b592 to 05b2429 Compare May 14, 2021 14:45
@Jean85 Jean85 modified the milestones: 4.1, 4.2 Aug 27, 2021
@github-actions
Copy link

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@github-actions github-actions bot closed this Jan 19, 2022
@ste93cry ste93cry deleted the fix-messenger-sync-errors branch February 13, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the Sentry\Integration\IgnoreErrorsIntegration so it unwraps messenger exceptions?
3 participants