[9.x] Improve developer facing Sqlite missing DB error message #45626
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.
Alternative to laravel/laravel#6075
Issue
There is an inconsistency between artisan and HTTP requests when using relative file paths as the SQLite database.
Reproduce it
Create a brand new Laravel project, use Sqlite as a database, run migrations, and interact with the database via Tinker.
Note:
DB_DATABASE
is unchanged and currently set to"laravel"
.Everything should have worked as expected. Now we will serve the project and visit the homepage.
Why this happens
When using a relative path in
DB_DATABASE
and starting Laravel from the project root via artisan, the relative path resolves to the same thing asbase_path('laravel')
.When using the same relative path from a web request, the root is no longer the project root. It is now the
public
directory, so the relative path resolves to the same thing aspublic_path('laravel')
./private/tmp/sqlite-test/laravel
< Artisan/private/tmp/sqlite-test/public/laravel
< Web requestWhen the SqliteConnector tries to resolve the realpath, it is unable to find the file
/private/tmp/sqlite-test/public/laravel
, so it returnsfalse
.framework/src/Illuminate/Database/Connectors/SQLiteConnector.php
Lines 28 to 37 in 1fea069
The improvement (not a fix)
The current exception message is not useful. In Laravel 9.x I would like to solve this by improving the error message presented to the user to at least give some information on how to solve the issue.
Unfortunately the error message doesn't mention the environment variable or the configuration variable, as at this point we don't have any information on which is being used. The component could also be used outside of
laravel/laravel
.Inconsistency sucks
You know it. I know it. It sucks that this works in Artisan but doesn't then work in a HTTP request. Just wanna put that out there.
Future fix
Someone smarter than myself may be able to find a good solution to this, but I've tried a bunch of things and everything seemed to have issues.
Windows vs POSIX,
./laravel
vslaravel
, who knows what else.