leventcz / laravel-top

πŸš€ Real-time monitoring from the command line for Laravel applications.
MIT License
512 stars 17 forks source link

Call to a member function uri() on null within RequestListener. #2

Closed corsair closed 6 months ago

corsair commented 6 months ago

Before anything, bravo on an incredible package, and I am very excited to see it grow. πŸ‘

Laravel V11.7.0 Octane V2.3.10 Laravel Top V1.0.1

There may be an issue with how the request event handling transpires with specific requests. Everything works as anticipated when accessing any route directly (via a web browser, for example). However, when attempting to access any routes via Axios or fetch (via Vue 3), the package results in the following error:

[2024-05-23 17:28:02] local.ERROR: Call to a member function uri() on null {"exception":"[object] (Error(code: 0): Call to a member function uri() on null at /Users/tylercorsair/Sites/x/x/vendor/leventcz/laravel-top/src/Listeners/RequestListener.php:20)
[stacktrace]
#0 /Users/tylercorsair/Sites/x/x/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(478): Leventcz\\Top\\Listeners\\RequestListener->requestHandled(Object(Illuminate\\Foundation\\Http\\Events\\RequestHandled))
#1 /Users/tylercorsair/Sites/x/x/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(286): Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}('Illuminate\\\\Foun...', Array)
#2 /Users/tylercorsair/Sites/x/x/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(266): Illuminate\\Events\\Dispatcher->invokeListeners('Illuminate\\\\Foun...', Array, false)
#3 /Users/tylercorsair/Sites/x/x/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Events\\Dispatcher->dispatch('Illuminate\\\\Foun...')
#4 /Users/tylercorsair/Sites/x/x/vendor/laravel/octane/src/ApplicationGateway.php(36): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))
#5 /Users/tylercorsair/Sites/x/x/vendor/laravel/octane/src/Worker.php(84): Laravel\\Octane\\ApplicationGateway->handle(Object(Illuminate\\Http\\Request))
#6 /Users/tylercorsair/Sites/x/x/vendor/laravel/octane/bin/swoole-server(120): Laravel\\Octane\\Worker->handle(Object(Illuminate\\Http\\Request), Object(Laravel\\Octane\\RequestContext))
#7 [internal function]: {closure}(Object(Swoole\\Http\\Request), Object(Swoole\\Http\\Response))
#8 /Users/tylercorsair/Sites/x/x/vendor/laravel/octane/bin/swoole-server(170): Swoole\\Server->start()
#9 {main}
"} 

Subsequently, this results in the request failing prematurely, with no data returned. Upon removing the package, the previous requests can succeed as expected.

Here is an example of an axios request that normally works without the package installed:

/// The Laravel Octane instance.
axios.get('http://localhost:5001/api/v1/test').then(response => {
     // Do something.
});

If it may help, here are the other packages installed in this repository:

"require": {
        "php": "^8.3",
        "aws/aws-sdk-php": "^3.231",
        "doctrine/dbal": "^3.0",
        "guzzlehttp/guzzle": "^7.8",
        "intervention/image": "^3.3.1",
        "laravel/framework": "^11.0",
        "laravel/horizon": "^5.20",
        "laravel/octane": "^v2.3.0",
        "laravel/pulse": "^1.0@beta",
        "laravel/sanctum": "^4.0",
        "laravel/telescope": "^5.0",
        "laravel/tinker": "^2.7",
        "laravel/ui": "^4.0",
        "league/flysystem": "^3.2",
        "league/flysystem-aws-s3-v3": "^3.0",
        "leventcz/laravel-top": "^1.0",
        "php-ffmpeg/php-ffmpeg": "^1.0",
        "predis/predis": "^2.0",
        "rosell-dk/webp-convert": "2.9.1",
        "symfony/http-client": "^7.0",
        "symfony/postmark-mailer": "^7.0"
    },
    "require-dev": {
        "fakerphp/faker": "1.14.1",
        "laravel/breeze": "^2.0",
        "laravel/sail": "^1.15",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^8.1",
        "nunomaduro/larastan": "^2.1",
        "phpstan/phpstan": "^1.8",
        "phpunit/phpunit": "^10.3.0",
        "spatie/laravel-ignition": "^2.0",
        "squizlabs/php_codesniffer": "^3.7"
    },

Cheers.

leventcz commented 6 months ago

Thank you for sharing the issue and your kind feedback.

It seems that routes are not being resolved during preflight requests. In the new release, I have added the necessary check.

v1.0.2

corsair commented 6 months ago

I can confirm this has been resolved! πŸ‘

Thank you for the swift response and resolution!