yii2-debug icon indicating copy to clipboard operation
yii2-debug copied to clipboard

Call to a member function getRequest() on null is RequestPanel.php file

Open vasyakrg opened this issue 5 years ago • 12 comments

Fatal error: Uncaught Error: Call to a member function getRequest() on null in /var/www/yii2/vendor/yiisoft/yii2-debug/src/panels/**RequestPanel.php on line 59**

Call Stack:
    0.0016     351728   1. {main}() /var/www/yii2/vendor/codeception/codeception/codecept:0
    0.5448    1842688   2. Codeception\Application->run(???, ???) /var/www/yii2/vendor/codeception/codeception/codecept:43
    0.5449    1842688   3. Codeception\Application->run(???, ???) /var/www/yii2/vendor/codeception/codeception/src/Codeception/Application.php:108

Error: Call to a member function getRequest() on null in /var/www/yii2/vendor/yiisoft/yii2-debug/src/panels/RequestPanel.php on line 59

Call Stack:
    0.0016     351728   1. {main}() /var/www/yii2/vendor/codeception/codeception/codecept:0
    0.5448    1842688   2. Codeception\Application->run(???, ???) /var/www/yii2/vendor/codeception/codeception/codecept:43
    0.5449    1842688   3. Codeception\Application->run(???, ???) /var/www/yii2/vendor/codeception/codeception/src/Codeception/Application.php:108
   18.4747    5267328   4. yii\log\Logger->flush(???) /var/www/yii2/vendor/yiisoft/yii2/log/Logger.php:0
   18.4747    5267328   5. yii\log\Dispatcher->dispatch(???, ???) /var/www/yii2/vendor/yiisoft/yii2/log/Logger.php:177
   18.4747    5267328   6. yii\debug\LogTarget->collect(???, ???) /var/www/yii2/vendor/yiisoft/yii2/log/Dispatcher.php:189
   18.4747    5267328   7. yii\debug\LogTarget->export() /var/www/yii2/vendor/yiisoft/yii2-debug/src/LogTarget.php:130
   18.4966    5295024   8. yii\debug\panels\RequestPanel->save() /var/www/yii2/vendor/yiisoft/yii2-debug/src/LogTarget.php:6

Additional info

Q A
Yii version 2.0.17
PHP version PHP 7.1.27 (cli)
Operating system Debian (docker)
codeception/codeception 2.5.5
yiisoft/yii2-debug 2.1.1

vasyakrg avatar Apr 12 '19 04:04 vasyakrg

decision:

on file: vendor/yiisoft/yii2-debug/src/panels/RequestPanel.php before: line 59 - $headers = Yii::$app->getRequest()->getHeaders(); add if (Yii::$app === null) {return '';}

vasyakrg avatar Apr 12 '19 04:04 vasyakrg

Thanks for posting in our issue tracker. In order to properly assist you, we need additional information:

  • When does the issue occur?
  • What do you see?
  • What was the expected result?
  • Can you supply us with a stacktrace? (optional)
  • Do you have exact code to reproduce it? Maybe a PHPUnit tests that fails? (optional)

Thanks!

This is an automated comment, triggered by adding the label status:need more info.

yii-bot avatar Apr 12 '19 09:04 yii-bot

It has been 2 or more weeks with no response on our request for more information. In order for our issue tracker to be effective, we are closing this issue.

If you want it to be reopened again, feel free to supply us with the requested information.

Thanks!

This is an automated comment, triggered by adding the label expired.

yii-bot avatar May 09 '19 22:05 yii-bot

I ran into the same issue, see https://travis-ci.org/dmstr/phd5-app/builds/540910183#L3086

The root cause was a "functional", which did not create any request but checked a version file. My solution was to move the test to the CLI suite. (VersionCept)

But nonetheless it's something we should care about, since all tests are green, but the pipeline still fails due to the error thrown under the hood.


[addon] My changes did not really fix the issue, still investigating...

schmunk42 avatar Jun 03 '19 19:06 schmunk42

So my fix or better workaround is this: https://github.com/dmstr/phd5-app/commit/54497262bbfb44e4af1ec9f3aabc6ce56424cbe9 - disabling the debug module in tests.

I had the issue also in unit tests.

Reopening ... how to proceed, do you need additional info?

schmunk42 avatar Jun 03 '19 22:06 schmunk42

Yes. Is that Codeception-specific?

samdark avatar Jun 03 '19 23:06 samdark

Had the exact same issue today, running g codeception too

machour avatar Jun 04 '19 03:06 machour

Yes. Is that Codeception-specific?

Yes, I had this after upgrading from 2.3 to 2.5

schmunk42 avatar Jun 04 '19 05:06 schmunk42

I just wrote a long post about register_shutdown_function... and then not posted it because it was wrong Turns out we already handle it: https://github.com/Codeception/Codeception/blob/3.0/src/Codeception/Lib/Connector/Yii2.php#L267

The source of the issue is register_shutdown_function which is (imo) a design flaw of Yii logging. The logging modules make assumptions about the state of the system which they shouldn't. By definition the shutdown function is always called and therefore no assumptions on the state should be made.

@schmunk42 can you check if the logger is getting replaced properly.

Side note: instead of overriding the logger class, we could probably do something like this:

namespace yii\log {
    function register_shutdown_function() {
        codecept_debug('Mocked register_shutdown_function called');
    }

SamMousa avatar Jun 04 '19 08:06 SamMousa

Like mentioned from @SamMousa using

namespace yii\log {

    function register_shutdown_function()
    {
        // Stop calling register_shutdown_function
    }

}

in _bootstrap.php (I put it in unit/ and functional/) is a better fix for this.

schmunk42 avatar Jun 04 '19 08:06 schmunk42

I'm putting this in codeception as well, since it's a better fix.

SamMousa avatar Jun 04 '19 09:06 SamMousa

I'm putting this in codeception as well, since it's a better fix.

Would be nice to see this in 2.x, since upgrading to 3.x raised even more issues.

schmunk42 avatar Jun 04 '19 10:06 schmunk42