Skip to content

Hyperf\Context\RequestContext::get(): Return value issue #73

Description

@foremtehan

PHP Version

8.4

Swoole Extension Version

6.0.2

Database Driver & Version

No response

Description

[2025-05-02 14:59:42 *403.0]  channel is destroyed, 1 consumers will be discarded
[2025-05-02 14:59:42 *403.0] Fatal error: Uncaught TypeError: Hyperf\Context\RequestContext::get(): Return value must be of type Swow\Psr7\Message\ServerRequestPlusInterface, null returned in /var/www/html/vendor/hyperf/context/src/RequestContext.php:23
Stack trace:
#0 /var/www/html/vendor/hyperf/http-server/src/Request.php(604): Hyperf\Context\RequestContext::get()
#1 /var/www/html/vendor/hyperf/http-server/src/Request.php(595): Hyperf\HttpServer\Request->getRequest()
#2 /var/www/html/vendor/hyperf/http-server/src/Request.php(391): Hyperf\HttpServer\Request->call()
#3 /var/www/html/app/Exceptions/TelegramLogHandler.php(19): Hyperf\HttpServer\Request->getBody()
#4 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/TelegramBotHandler.php(250): App\Exceptions\TelegramLogHandler->sendCurl()
#5 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/TelegramBotHandler.php(235): Monolog\Handler\TelegramBotHandler->send()
#6 /var/www/html/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(44): Monolog\Handler\TelegramBotHandler->write()
#7 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(391): Monolog\Handler\AbstractProcessingHandler->handle()
#8 /var/www/html/vendor/monolog/monolog/src/Monolog/Logger.php(646): Monolog\Logger->addRecord()
#9 /var/www/html/vendor/hypervel/log/src/Logger.php(138): Monolog\Logger->error()
#10 /var/www/html/vendor/hypervel/log/src/Logger.php(65): Hypervel\Log\Logger->writeLog()
#11 /var/www/html/vendor/hypervel/log/src/LogManager.php(588): Hypervel\Log\Logger->error()
#12 /var/www/html/vendor/hypervel/foundation/src/Exceptions/Handler.php(311): Hypervel\Log\LogManager->error()
#13 /var/www/html/vendor/hypervel/foundation/src/Exceptions/Handler.php(270): Hypervel\Foundation\Exceptions\Handler->reportThrowable()
#14 /var/www/html/vendor/hypervel/coroutine/src/Coroutine.php(26): Hypervel\Foundation\Exceptions\Handler->report()
#15 /var/www/html/vendor/hyperf/coroutine/src/Coroutine.php(82): Hypervel\Coroutine\Coroutine::printLog()
#16 [internal function]: Hyperf\Coroutine\Coroutine::{closure:Hyperf\Coroutine\Coroutine::create():78}()
#17 {main}
  thrown in /var/www/html/vendor/hyperf/context/src/RequestContext.php on line 23

Steps To Reproduce

request()->getBody()->getContents();

Activity

  1. added
    not enough infoA maintainer has requested additional information from the reporter.
    on May 2, 2025
  2. albertcht commented on May 2, 2025

    @albertcht
    Member

    It happened when there's exception happening in the coroutine?
    You didn't provide the detailed reproducible steps. Unable to reproduce it.

    It looks like something went wrong in your own TelegramBotHandler?

  3. foremtehan commented on May 2, 2025

    @foremtehan
    ContributorAuthor

    The error happens when we call request()->getBody()->getContents(); out of Http context, For example if you call it in php artisan tinker

  4. albertcht commented on May 3, 2025

    @albertcht
    Member

    out of Http context, For example if you call it in php artisan tinker

    This is a really important message! It's very misleading without it. Please describe your questions in as much detail as possible next time, thanks.

    I think this is an expected error since the request is only available in HTTP environment.

  5. locked and limited conversation to collaborators on May 3, 2025
  6. converted this issue into a discussion #74 on May 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    not enough infoA maintainer has requested additional information from the reporter.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions