From 93a4c36600fd50716efcc2432529968910366d67 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 31 Mar 2021 15:45:12 +0200 Subject: [PATCH 1/2] Intercept failures in the RequestFetcher --- src/Integration/RequestFetcher.php | 6 +++++- tests/Integration/RequestFetcherTest.php | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Integration/RequestFetcher.php b/src/Integration/RequestFetcher.php index e471da9d..f5911b2c 100644 --- a/src/Integration/RequestFetcher.php +++ b/src/Integration/RequestFetcher.php @@ -56,6 +56,10 @@ public function fetchRequest(): ?ServerRequestInterface return null; } - return $this->httpMessageFactory->createRequest($request); + try { + return $this->httpMessageFactory->createRequest($request); + } catch (\Throwable $exception) { + return null; + } } } diff --git a/tests/Integration/RequestFetcherTest.php b/tests/Integration/RequestFetcherTest.php index ec339f17..62597ce3 100644 --- a/tests/Integration/RequestFetcherTest.php +++ b/tests/Integration/RequestFetcherTest.php @@ -54,8 +54,21 @@ public function testFetchRequest(?Request $request, ?ServerRequestInterface $exp $this->assertSame($expectedRequest, $this->requestFetcher->fetchRequest()); } + public function testFetchRequestFailsSilently(): void + { + $this->requestStack->expects($this->once()) + ->method('getCurrentRequest') + ->willReturn(new Request()); + + $this->httpMessageFactory->expects($this->once()) + ->method('createRequest') + ->willThrowException(new \Exception()); + + $this->assertNull($this->requestFetcher->fetchRequest()); + } + /** - * @return \Generator + * @return \Generator */ public function fetchRequestDataProvider(): \Generator { From 11fcaef6e21973f11b1959827ff28c3c649561d0 Mon Sep 17 00:00:00 2001 From: Alessandro Lai Date: Wed, 31 Mar 2021 15:47:14 +0200 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb19e2ff..839384f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Avoid failures when the `RequestFetcher` fails to translate the `Request` (#472) ## 4.0.3 (2021-03-03) - Fix regression from #454 for `null` value on DSN not disabling Sentry (#457) @@ -46,7 +47,7 @@ using an on-premise installation it requires Sentry version `>= v20.6.0` to work - Use `jean85/pretty-package-versions` `^1.5` to leverage the new `getRootPackageVersion` method (c8799ac) - Fix support for PHP preloading (#354, thanks to @annuh) -- Fix `capture_soft_fails: false` option for the Messenger (#353) +- Fix `capture_soft_fails: false` option for the Messenger (#353) ## 3.5.1 (2020-05-07)