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

PDO: If empty database there is a stacktrace #349

Closed
Mte90 opened this issue Oct 19, 2020 · 10 comments · Fixed by #351
Closed

PDO: If empty database there is a stacktrace #349

Mte90 opened this issue Oct 19, 2020 · 10 comments · Fixed by #351

Comments

@Mte90
Copy link
Contributor

Mte90 commented Oct 19, 2020

I am getting General error: 1 no such table: results with an empty sqlite file.

#0 /srv/www/default/xhgui/src/Xhgui/Db/PdoRepository.php(90): PDO->prepare('\n          SELE...')
#1 /srv/www/default/xhgui/src/Xhgui/Searcher/PdoSearcher.php(108): XHGui\Db\PdoRepository->countByUrl('')
#2 /srv/www/default/xhgui/src/Xhgui/Controller/RunController.php(48): XHGui\Searcher\PdoSearcher->getAll(Array)
#3 /srv/www/default/xhgui/src/routes.php(45): XHGui\Controller\RunController->index(Object(Slim\Http\Request), Object(Slim\Http\Response))
#4 [internal function]: {closure}()
#5 /srv/www/default/xhgui/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)
#6 /srv/www/default/xhgui/vendor/slim/slim/Slim/Slim.php(1355): Slim\Route->dispatch()
#7 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call()
#8 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call()
#9 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/SessionCookie.php(110): Slim\Middleware\MethodOverride->call()
#10 /srv/www/default/xhgui/src/Xhgui/Middleware/RenderMiddleware.php(14): Slim\Middleware\SessionCookie->call()
#11 /srv/www/default/xhgui/vendor/slim/slim/Slim/Slim.php(1300): XHGui\Middleware\RenderMiddleware->call()
#12 /srv/www/default/xhgui/webroot/index.php(13): Slim\Slim->run()
#13 {main}

If I run xhgui in a page with tideways the error changes and the file now has some content.

I get another error Undefined variable: direction:

#0 /srv/www/default/xhgui/src/Xhgui/Searcher/PdoSearcher.php(116): Slim\Slim::handleErrors(8, 'Undefined varia...', '/srv/www/defaul...', 116, Array)
#1 /srv/www/default/xhgui/src/Xhgui/Controller/RunController.php(48): XHGui\Searcher\PdoSearcher->getAll(Array)
#2 /srv/www/default/xhgui/src/routes.php(45): XHGui\Controller\RunController->index(Object(Slim\Http\Request), Object(Slim\Http\Response))
#3 [internal function]: {closure}()
#4 /srv/www/default/xhgui/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)
#5 /srv/www/default/xhgui/vendor/slim/slim/Slim/Slim.php(1355): Slim\Route->dispatch()
#6 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim->call()
#7 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/MethodOverride.php(92): Slim\Middleware\Flash->call()
#8 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/SessionCookie.php(110): Slim\Middleware\MethodOverride->call()
#9 /srv/www/default/xhgui/src/Xhgui/Middleware/RenderMiddleware.php(14): Slim\Middleware\SessionCookie->call()
#10 /srv/www/default/xhgui/vendor/slim/slim/Slim/Slim.php(1300): XHGui\Middleware\RenderMiddleware->call()
#11 /srv/www/default/xhgui/webroot/index.php(13): Slim\Slim->run()
#12 {main}

Looking at

foreach ($this->db->findByUrl($url, $direction, $skip, $perPage) as $row) {
that variable indeed is not defined at all in that function.

So I guess that they are 2 different issues, an empty db that is not filled with tables and a bad refactoring (maybe?).

Ref: Varying-Vagrant-Vagrants/VVV#2261

@glensc
Copy link
Contributor

glensc commented Oct 19, 2020

one issue per one problem, please.

does your problem go away if you record one profiling? previously all SQL errors were ignored, so as a result the error is now thrown that was previously ignored.

glensc added a commit that referenced this issue Oct 19, 2020
@Mte90
Copy link
Contributor Author

Mte90 commented Oct 20, 2020

Thanks for the fix.
About the first issue, as I can see the sqlite file is created but is just empty with no table, so when you open xhgui you get an error with the stacktrace (that mention to check mongo also if not used).
So maybe a more welcome message like "do some scans with xhgui so this page will be filled" (my english is horrible) is better.

@glensc
Copy link
Contributor

glensc commented Oct 20, 2020

this isn't solved yet. the issue was closed automatically due to the merge and you reporting two problems in one issue. so only 50% is fixed.

@glensc glensc reopened this Oct 20, 2020
@glensc
Copy link
Contributor

glensc commented Oct 20, 2020

perhaps opening SQLite db creates the file. I'm thinking of lazy init the table if an error of unknown table occurs.

@Mte90
Copy link
Contributor Author

Mte90 commented Oct 20, 2020

Seems a good idea so it is less heavy for performance.

@glensc
Copy link
Contributor

glensc commented Oct 20, 2020

also, you did not reply to my question:

does your problem go away if you record one profiling?

@Mte90
Copy link
Contributor Author

Mte90 commented Oct 20, 2020

Sorry I am testing everything now and I get this error inside XHGUI:

<b>Fatal error</b>:  Uncaught TypeError: Argument 2 passed to XHGui\Db\PdoRepository::findByUrl() must be of the type string, null given, called in /srv/www/default/xhgui/src/Xhgui/Searcher/PdoSearcher.php on line 117 and defined in /srv/www/default/xhgui/src/Xhgui/Db/PdoRepository.php:96
Stack trace:
#0 /srv/www/default/xhgui/src/Xhgui/Searcher/PdoSearcher.php(117): XHGui\Db\PdoRepository-&gt;findByUrl('', NULL, 0, 25)
#1 /srv/www/default/xhgui/src/Xhgui/Controller/RunController.php(48): XHGui\Searcher\PdoSearcher-&gt;getAll(Array)
#2 /srv/www/default/xhgui/src/routes.php(45): XHGui\Controller\RunController-&gt;index(Object(Slim\Http\Request), Object(Slim\Http\Response))
#3 [internal function]: {closure}()
#4 /srv/www/default/xhgui/vendor/slim/slim/Slim/Route.php(468): call_user_func_array(Object(Closure), Array)
#5 /srv/www/default/xhgui/vendor/slim/slim/Slim/Slim.php(1355): Slim\Route-&gt;dispatch()
#6 /srv/www/default/xhgui/vendor/slim/slim/Slim/Middleware/Flash.php(85): Slim\Slim-&gt;call()
#7 /srv/www/default/xhgui/vendor/slim/slim/Slim/M in <b>/srv/www/default/xhgui/src/Xhgui/Db/PdoRepository.php</b> on line <b>96</b><br />

Also if I profile a page.

@glensc
Copy link
Contributor

glensc commented Oct 22, 2020

The submit some profiling message dialog is already there

Looks like you haven't done any profiling
To get started with XHGUI you'll need to collect some profiling data.

See Profiling a Web Request or CLI script section of the readme file

@glensc
Copy link
Contributor

glensc commented Oct 22, 2020

Initialize schema on PdoRepository construction:

if someone wishes to make it on demand, I would not say no to a PR that does it portably :)

@glensc glensc changed the title If empty database there is a stacktrace PDO: If empty database there is a stacktrace Oct 22, 2020
@glensc glensc closed this as completed Oct 22, 2020
@Mte90
Copy link
Contributor Author

Mte90 commented Oct 22, 2020

Seems everything fixed now :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants