-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Show better message when SQLite is not enabled #431
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
12e1f55
Implemented to catch exception, when SQLite is not enabled and show b…
uikolas d5a8829
Edited to catch sqlite exception in one event subscriber
uikolas cda028c
Small Code standard fix
uikolas e284eff
Added to check if driver exception occurred
uikolas b19f5d4
Added to check main exception
uikolas b1ebee4
Added to check if SQLite is used as database
uikolas 239f1c2
Merge pull request #1 from symfony/master
uikolas 04badea
Merge remote-tracking branch 'origin/master' into fix-423
uikolas 3d20d31
Check if database platform exists
uikolas d90a80c
code clean
uikolas 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 |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
use Symfony\Component\Console\Event\ConsoleExceptionEvent; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
/** | ||
* This application uses by default an SQLite database to store its information. | ||
|
@@ -24,7 +26,7 @@ | |
* | ||
* @author Javier Eguiluz <[email protected]> | ||
*/ | ||
class ConsoleEventSubscriber implements EventSubscriberInterface | ||
class CheckSQLiteEventSubscriber implements EventSubscriberInterface | ||
{ | ||
// Event Subscribers must define this method to declare the events they | ||
// listen to. You can listen to several events, execute more than one method | ||
|
@@ -36,6 +38,8 @@ public static function getSubscribedEvents() | |
// Exceptions are one of the events defined by the Console. See the | ||
// rest here: http://symfony.com/doc/current/components/console/events.html | ||
ConsoleEvents::EXCEPTION => 'handleDatabaseExceptions', | ||
// See: http://api.symfony.com/3.2/Symfony/Component/HttpKernel/KernelEvents.html | ||
KernelEvents::EXCEPTION => 'onKernelException', | ||
]; | ||
} | ||
|
||
|
@@ -57,4 +61,16 @@ public function handleDatabaseExceptions(ConsoleExceptionEvent $event) | |
} | ||
} | ||
} | ||
|
||
/** | ||
* This method is triggered when kernel exception occurs. And checks if sqlite extension is enabled. | ||
* | ||
* @param GetResponseForExceptionEvent $event | ||
*/ | ||
public function onKernelException(GetResponseForExceptionEvent $event) | ||
{ | ||
if (!extension_loaded('sqlite3')) { | ||
$event->setException(new \Exception('PHP extension "sqlite3" must be enabled because, by default, the Symfony Demo application uses SQLite to store its information.')); | ||
} | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be done only if the exception is a DBAL exception IMO. Otherwise, it could hide other issues happening earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, i agree with that. But the problem is that from $event->getException() i get Twig_Error_Runtime and don't know why. Maybe is documented somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, any exception thrown during a Twig template rendering is wrapped in a Twig_Error_Runtime. You can check the chain of previous exceptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, didn't know that. Ok :)