-
Notifications
You must be signed in to change notification settings - Fork 35
Update error handler add stack trace #188
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -718,22 +718,23 @@ public function testErrorHandlerFailure(): void | |
| ->error() | ||
| ->inject('error') | ||
| ->action(function ($error) { | ||
| throw new \Exception('Error handler failed'); | ||
| throw new Exception('Error handler failed'); | ||
| }); | ||
|
|
||
| $route = new Route('GET', '/path'); | ||
| $route | ||
| ->action(function () { | ||
| throw new \Exception('Route action failed'); | ||
| throw new Exception('Route action failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| try { | ||
| $this->app->execute($route, new Request(), new Response()); | ||
| $this->fail('Should have thrown an exception'); | ||
| } catch (\Exception $e) { | ||
| $this->assertEquals('Error handler had an error: Error handler failed', $e->getMessage()); | ||
| } catch (Exception $e) { | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertStringStartsWith('Error handler had an error: Error handler failed', $e->getMessage()); | ||
| $this->assertStringContainsString('Stack trace:', $e->getMessage()); | ||
| $this->assertEquals(500, $e->getCode()); | ||
| $this->assertInstanceOf(\Exception::class, $e->getPrevious()); | ||
| $this->assertInstanceOf(Exception::class, $e->getPrevious()); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertEquals('Error handler failed', $e->getPrevious()->getMessage()); | ||
| } | ||
| } | ||
|
|
@@ -744,13 +745,13 @@ public function testOptionsHandlerFailure(): void | |
| ->error() | ||
| ->inject('error') | ||
| ->action(function ($error) { | ||
| throw new \Exception('Options error handler failed'); | ||
| throw new Exception('Options error handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| // Set up an options handler that throws | ||
| App::options() | ||
| ->action(function () { | ||
| throw new \Exception('Options handler failed'); | ||
| throw new Exception('Options handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| $request = new UtopiaRequestTest(); | ||
|
|
@@ -759,8 +760,9 @@ public function testOptionsHandlerFailure(): void | |
| try { | ||
| $this->app->run($request, new Response()); | ||
| $this->fail('Should have thrown an exception'); | ||
| } catch (\Exception $e) { | ||
| $this->assertEquals('Error handler had an error: Options error handler failed', $e->getMessage()); | ||
| } catch (Exception $e) { | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertStringStartsWith('Error handler had an error: Options error handler failed', $e->getMessage()); | ||
| $this->assertStringContainsString('Stack trace:', $e->getMessage()); | ||
| $this->assertEquals(500, $e->getCode()); | ||
| } | ||
| } | ||
|
|
@@ -771,7 +773,7 @@ public function testNotFoundErrorHandlerFailure(): void | |
| $this->app | ||
| ->error() | ||
| ->action(function () { | ||
| throw new \Exception('404 error handler failed'); | ||
| throw new Exception('404 error handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| $request = new UtopiaRequestTest(); | ||
|
|
@@ -781,10 +783,11 @@ public function testNotFoundErrorHandlerFailure(): void | |
| try { | ||
| $this->app->run($request, new Response()); | ||
| $this->fail('Should have thrown an exception'); | ||
| } catch (\Exception $e) { | ||
| $this->assertEquals('Error handler had an error: 404 error handler failed', $e->getMessage()); | ||
| } catch (Exception $e) { | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertStringStartsWith('Error handler had an error: 404 error handler failed', $e->getMessage()); | ||
| $this->assertStringContainsString('Stack trace:', $e->getMessage()); | ||
| $this->assertEquals(500, $e->getCode()); | ||
| $this->assertInstanceOf(\Exception::class, $e->getPrevious()); | ||
| $this->assertInstanceOf(Exception::class, $e->getPrevious()); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertEquals('404 error handler failed', $e->getPrevious()->getMessage()); | ||
| } | ||
| } | ||
|
|
@@ -796,23 +799,24 @@ public function testGroupErrorHandlerFailure(): void | |
| ->error() | ||
| ->groups(['api']) | ||
| ->action(function () { | ||
| throw new \Exception('Group error handler failed'); | ||
| throw new Exception('Group error handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| $route = new Route('GET', '/api/test'); | ||
| $route | ||
| ->groups(['api']) | ||
| ->action(function () { | ||
| throw new \Exception('Route action failed'); | ||
| throw new Exception('Route action failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| try { | ||
| $this->app->execute($route, new Request(), new Response()); | ||
| $this->fail('Should have thrown an exception'); | ||
| } catch (\Exception $e) { | ||
| $this->assertEquals('Error handler had an error: Group error handler failed', $e->getMessage()); | ||
| } catch (Exception $e) { | ||
|
||
| $this->assertStringStartsWith('Error handler had an error: Group error handler failed', $e->getMessage()); | ||
| $this->assertStringContainsString('Stack trace:', $e->getMessage()); | ||
| $this->assertEquals(500, $e->getCode()); | ||
| $this->assertInstanceOf(\Exception::class, $e->getPrevious()); | ||
| $this->assertInstanceOf(Exception::class, $e->getPrevious()); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertEquals('Group error handler failed', $e->getPrevious()->getMessage()); | ||
| } | ||
| } | ||
|
|
@@ -824,31 +828,32 @@ public function testErrorHandlerChaining(): void | |
| ->error() | ||
| ->groups(['api']) | ||
| ->action(function () { | ||
| throw new \Exception('First error handler failed'); | ||
| throw new Exception('First error handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| $this->app | ||
| ->error() | ||
| ->action(function () { | ||
| throw new \Exception('Second error handler failed'); | ||
| throw new Exception('Second error handler failed'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| $route = new Route('GET', '/api/test'); | ||
| $route | ||
| ->groups(['api']) | ||
| ->action(function () { | ||
| throw new \Exception('Original error'); | ||
| throw new Exception('Original error'); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| try { | ||
| $this->app->execute($route, new Request(), new Response()); | ||
| $this->fail('Should have thrown an exception'); | ||
| } catch (\Exception $e) { | ||
| $this->assertEquals('Error handler had an error: First error handler failed', $e->getMessage()); | ||
| } catch (Exception $e) { | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertStringStartsWith('Error handler had an error: First error handler failed', $e->getMessage()); | ||
| $this->assertStringContainsString('Stack trace:', $e->getMessage()); | ||
| $this->assertEquals(500, $e->getCode()); | ||
|
|
||
| // Verify the error chain | ||
| $this->assertInstanceOf(\Exception::class, $e->getPrevious()); | ||
| $this->assertInstanceOf(Exception::class, $e->getPrevious()); | ||
ChiragAgg5k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertEquals('First error handler failed', $e->getPrevious()->getMessage()); | ||
| } | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.