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

Stacktrace and debugging #100

Closed
rodion-k opened this issue Nov 17, 2020 · 6 comments
Closed

Stacktrace and debugging #100

rodion-k opened this issue Nov 17, 2020 · 6 comments

Comments

@rodion-k
Copy link

Hi!
Is there a way to get a location where a query was called when QueryError occurs?
For example

1 <?php
      2 
      3 ini_set("log_errors_max_len",0);
      4 
      5 require __DIR__ . '/vendor/autoload.php';
      6 
      7 \Amp\Loop::run(function () {
      8     yield query();
      9 });
     10 
     11 function query() {
     12     return \Amp\call(function () {
     13         $config = Amp\Mysql\ConnectionConfig::fromString(
     14             "host=127.0.0.1 port=33306 user=root password=pass db=test"
     15         );
     16 
     17         /** @var \Amp\Mysql\Pool $pool */
     18         $pool = Amp\Mysql\pool($config);
     19 
     20         $result = yield $pool->query("SELECT * FROM test");
     21 
     22         while (yield $result->advance()) {
     23             var_dump($result->getCurrent());
     24         }
     25     });
     26 }

Produces error:

PHP Fatal error:  Uncaught Amp\Sql\QueryError: MySQL error (1146): #42S02 Table 'test.test' doesn't exist
Current query was SELECT * FROM test in /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php:707
Stack trace:
#0 /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php(902): Amp\Mysql\Internal\Processor->handleError()
#1 /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php(1433): Amp\Mysql\Internal\Processor->handleQuery()
#2 /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php(294): Amp\Mysql\Internal\Processor->parsePayload()
#3 /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php(261): Amp\Mysql\Internal\Processor->processData()
#4 [internal function]: Amp\Mysql\Internal\Processor->read()
#5 /home/rodion/.config/composer/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send()
#6 /home/rodion/.config/composer/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}()
#7 /home/rodion/.config/composer/vendor/amphp/amp/lib/Deferred.php(52): class@anonymous->resolve()
#8 /home/rodion/.config/composer/vendor/amphp/byte-stream/lib/ResourceInputStream.php(101): Amp\Deferred->resolve()
#9 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop/NativeDriver.php(183): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}()
#10 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop/NativeDriver.php(96): Amp\Loop\NativeDriver->selectStreams()
#11 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch()
#12 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#13 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop/TracingDriver.php(27): Amp\Loop\Driver->run()
#14 /home/rodion/.config/composer/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\TracingDriver->run()
#15 /home/rodion/.config/composer/amp-debug.php(9): Amp\Loop::run()
#16 {main}
  thrown in /home/rodion/.config/composer/vendor/amphp/mysql/src/Internal/Processor.php on line 707

Line 20, where the query was actually called, not present in stacktrace.

Thank you.

@bwoebi
Copy link
Member

bwoebi commented Nov 18, 2020

@trowski or @kelunik Can we manipulate the stacktrace to include ReflectionGenerator::getTrace() before throwing into the Generator? Then we'd have at least the full application side stacktrace, beneficial to the app devs themselves. (obviously v3 solves, that … mostly)

@kelunik
Copy link
Member

kelunik commented Nov 18, 2020

We might be able to do that, I think @danog hacked something for his coroutine implementation.

@danog
Copy link

danog commented Nov 19, 2020

@magussiro
Copy link

any further update?

@kelunik
Copy link
Member

kelunik commented Mar 25, 2021

Fibers will solve this in PHP 8.1+.

@trowski
Copy link
Member

trowski commented Feb 27, 2022

Closing this as I believe the original question has been answered. There's not much we can do about stack traces with Amp v2. Hopefully this will be much better with Amp v3 and fibers.

@trowski trowski closed this as completed Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants