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

[BUG] 当有多个异常处理器时,对象注入失败 #9

Closed
minxinqing opened this issue Jun 21, 2019 · 2 comments
Closed

[BUG] 当有多个异常处理器时,对象注入失败 #9

minxinqing opened this issue Jun 21, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@minxinqing
Copy link
Contributor

  • Hyperf Version: 1.0.0
  • PHP Version: (php -v) 7.2.18
  • Swoole Version: (php --ri swoole) 4.3.5

Description:

当有多个异常处理器时,异常处理器中handle方法注入失败。

Steps To Reproduce:

新增异常处理器,app/Exception/Handler/OrderExceptionHandler.php

<?php
namespace App\Exception\Handler;

use Hyperf\ExceptionHandler\ExceptionHandler;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Psr\Http\Message\ResponseInterface;
use Throwable;
use App\Exception\OrderException;
use App\Helper\Log;

class OrderExceptionHandler extends ExceptionHandler
{

    public function handle(Throwable $throwable, ResponseInterface $response)
    {
       
    }

    public function isValid(Throwable $throwable): bool
    {
        return true;
    }
}

注册异常处理器

return [
    'handler' => [
        'http' => [
            App\Exception\Handler\OrderExceptionHandler::class,
            App\Exception\Handler\AppExceptionHandler::class,
        ],
    ],
];

控制器诱发异常

$request->header();

控制台显示注入异常
image

@minxinqing minxinqing added the bug Something isn't working label Jun 21, 2019
@limingxinleo
Copy link
Member

handle 里不能什么都不返回。。。

handle 方法体里 加上以下代码试试

return $response;

@minxinqing
Copy link
Contributor Author

minxinqing commented Jun 21, 2019

handle 里不能什么都不返回。。。

handle 方法体里 加上以下代码试试

return $response;

为空表示当前异常处理类不处理这个异常,交由下一个异常处理类处理,我理解错了吗?
image

kingIZZZY added a commit to kingIZZZY/hyperf that referenced this issue Jan 18, 2023
Not sure what the correct fix should be... other PDO drivers might have `exec` method, but  [Swoole\Coroutine\PostgreSQL does not](https://github.com/swoole/swoole-src/blob/master/ext-src/swoole_postgresql_coro.cc#L396)

```log
[ERROR] Error: Call to undefined method Swoole\Coroutine\PostgreSQL::exec() in /opt/www/vendor/hyperf/database/src/Connection.php:390
Stack trace:
#0 /opt/www/vendor/hyperf/database/src/Connection.php(1054): Hyperf\Database\Connection->Hyperf\Database\{closure}()
hyperf#1 /opt/www/vendor/hyperf/database/src/Connection.php(1018): Hyperf\Database\Connection->runQueryCallback()
hyperf#2 /opt/www/vendor/hyperf/database/src/Connection.php(394): Hyperf\Database\Connection->run()
hyperf#3 /opt/www/vendor/hyperf/db-connection/src/Connection.php(48): Hyperf\Database\Connection->unprepared()
hyperf#4 /opt/www/vendor/hyperf/db-connection/src/Traits/DbConnection.php(76): Hyperf\DbConnection\Connection->__call()
hyperf#5 /opt/www/vendor/hyperf/db-connection/src/Db.php(66): Hyperf\DbConnection\Connection->unprepared()
hyperf#6 /opt/www/migrations/2023_01_18_181219_create_scrape_log_table.php(24): Hyperf\DbConnection\Db::__callStatic()
hyperf#7 /opt/www/vendor/hyperf/database/src/Migrations/Migrator.php(451): CreateScrapeLogTable->up()
hyperf#8 /opt/www/vendor/hyperf/database-pgsql/src/Concerns/PostgreSqlSwooleExtManagesTransactions.php(34): Hyperf\Database\Migrations\Migrator->Hyperf\Database\Migrations\{closure}()
hyperf#9 /opt/www/vendor/hyperf/db-connection/src/Connection.php(48): Hyperf\Database\PgSQL\PostgreSqlSwooleExtConnection->transaction()
hyperf#10 /opt/www/vendor/hyperf/db-connection/src/Traits/DbConnection.php(86): Hyperf\DbConnection\Connection->__call()
hyperf#11 /opt/www/vendor/hyperf/database/src/Migrations/Migrator.php(459): Hyperf\DbConnection\Connection->transaction()
hyperf#12 /opt/www/vendor/hyperf/database/src/Migrations/Migrator.php(327): Hyperf\Database\Migrations\Migrator->runMigration()
hyperf#13 /opt/www/vendor/hyperf/database/src/Migrations/Migrator.php(114): Hyperf\Database\Migrations\Migrator->runUp()
hyperf#14 /opt/www/vendor/hyperf/database/src/Migrations/Migrator.php(80): Hyperf\Database\Migrations\Migrator->runPending()
hyperf#15 /opt/www/vendor/hyperf/database/src/Commands/Migrations/MigrateCommand.php(48): Hyperf\Database\Migrations\Migrator->run()
hyperf#16 /opt/www/vendor/hyperf/command/src/Command.php(423): Hyperf\Database\Commands\Migrations\MigrateCommand->handle()
hyperf#17 [internal function]: Hyperf\Command\Command->Hyperf\Command\{closure}()
hyperf#18 {main}```

A few other calls in the source to consider:
- hyperf/database/src/Concerns/ManagesTransactions.php
    - https://github.com/hyperf/hyperf/blob/master/src/database/src/Concerns/ManagesTransactions.php#L182
    - https://github.com/hyperf/hyperf/blob/master/src/database/src/Concerns/ManagesTransactions.php#L215
- hyperf/database-pgsql/src/Concerns/PostgreSqlSwooleExtManagesTransactions.php
    - https://github.com/hyperf/hyperf/blob/master/src/database-pgsql/src/Concerns/PostgreSqlSwooleExtManagesTransactions.php#L182
    - https://github.com/hyperf/hyperf/blob/master/src/database-pgsql/src/Concerns/PostgreSqlSwooleExtManagesTransactions.php#L215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants