laravel / lumen-framework

The Laravel Lumen Framework.
https://lumen.laravel.com
MIT License
1.48k stars 416 forks source link

$this->fail() throws Exception Undefined array key "job" #1217

Closed SubrataM3 closed 2 years ago

SubrataM3 commented 2 years ago

Description:

$this->fail() throws Exception Undefined array key "job" when running a job via $this->dispatchNow method()

Stack Trace:

[2022-02-14 20:08:36] local.ERROR: Undefined array key "job" {"exception":"[object] (ErrorException(code: 0): Undefined array key \"job\" at /srv/html/api/vendor/illuminate/queue/Jobs/Job.php:210)
[stacktrace]
#0 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php(47): Laravel\\Lumen\\Application->handleError()
#1 /srv/html/api/vendor/illuminate/queue/Jobs/Job.php(210): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()
#2 /srv/html/api/vendor/illuminate/queue/Jobs/Job.php(192): Illuminate\\Queue\\Jobs\\Job->failed()
#3 /srv/html/api/vendor/illuminate/queue/InteractsWithQueue.php(47): Illuminate\\Queue\\Jobs\\Job->fail()
#4 /srv/html/api/app/Jobs/GoodJob.php(109): App\\Jobs\\Job->fail()
#5 /srv/html/api/vendor/illuminate/container/BoundMethod.php(36): App\\Jobs\\GoodJob->handle()
#6 /srv/html/api/vendor/illuminate/container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#7 /srv/html/api/vendor/illuminate/container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#8 /srv/html/api/vendor/illuminate/container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#9 /srv/html/api/vendor/illuminate/container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#10 /srv/html/api/vendor/illuminate/bus/Dispatcher.php(128): Illuminate\\Container\\Container->call()
#11 /srv/html/api/vendor/illuminate/pipeline/Pipeline.php(128): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}()
#12 /srv/html/api/vendor/illuminate/pipeline/Pipeline.php(103): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#13 /srv/html/api/vendor/illuminate/bus/Dispatcher.php(132): Illuminate\\Pipeline\\Pipeline->then()
#14 /srv/html/api/vendor/laravel/lumen-framework/src/Routing/ProvidesConvenienceMethods.php(204): Illuminate\\Bus\\Dispatcher->dispatchNow()
#15 /srv/html/api/app/Http/Controllers/UsersController.php(79): Laravel\\Lumen\\Routing\\Controller->dispatchNow()
#16 /srv/html/api/vendor/illuminate/container/BoundMethod.php(36): App\\Http\\Controllers\\UsersController->create()
#17 /srv/html/api/vendor/illuminate/container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#18 /srv/html/api/vendor/illuminate/container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#19 /srv/html/api/vendor/illuminate/container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#20 /srv/html/api/vendor/illuminate/container/Container.php(653): Illuminate\\Container\\BoundMethod::call()
#21 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(389): Illuminate\\Container\\Container->call()
#22 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(355): Laravel\\Lumen\\Application->callControllerCallable()
#23 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(329): Laravel\\Lumen\\Application->callLumenController()
#24 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(282): Laravel\\Lumen\\Application->callControllerAction()
#25 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(262): Laravel\\Lumen\\Application->callActionOnArrayBasedRoute()
#26 /srv/html/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(48): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()
#27 /srv/html/api/vendor/illuminate/routing/Middleware/ThrottleRequests.php(127): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()
#28 /srv/html/api/vendor/illuminate/routing/Middleware/ThrottleRequests.php(63): Illuminate\\Routing\\Middleware\\ThrottleRequests->handleRequest()
#29 /srv/html/api/vendor/illuminate/pipeline/Pipeline.php(167): Illuminate\\Routing\\Middleware\\ThrottleRequests->handle()
#30 /srv/html/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /srv/html/api/app/Http/Middleware/Authenticate.php(33): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()
#32 /srv/html/api/vendor/illuminate/pipeline/Pipeline.php(167): App\\Http\\Middleware\\Authenticate->handle()
#33 /srv/html/api/vendor/laravel/lumen-framework/src/Routing/Pipeline.php(30): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /srv/html/api/vendor/illuminate/pipeline/Pipeline.php(103): Laravel\\Lumen\\Routing\\Pipeline->Laravel\\Lumen\\Routing\\{closure}()
#35 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(426): Illuminate\\Pipeline\\Pipeline->then()
#36 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(263): Laravel\\Lumen\\Application->sendThroughPipeline()
#37 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(169): Laravel\\Lumen\\Application->handleFoundRoute()
#38 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(429): Laravel\\Lumen\\Application->Laravel\\Lumen\\Concerns\\{closure}()
#39 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(175): Laravel\\Lumen\\Application->sendThroughPipeline()
#40 /srv/html/api/vendor/laravel/lumen-framework/src/Concerns/RoutesRequests.php(112): Laravel\\Lumen\\Application->dispatch()
#41 /srv/html/api/public/index.php(28): Laravel\\Lumen\\Application->run()
#42 {main}
"} 

Steps To Reproduce:

1) Create a new job class and add $this->fail(); within it's handle method. 2) Then run the job using $this->dispatchNow(new GoodJob($request->all()));

driesvints commented 2 years ago

Seems this affects Laravel as well. I'm not sure what the expected behavior here would be. I made a PR with a failing test to follow up for Taylor: https://github.com/laravel/framework/pull/41008

driesvints commented 2 years ago

Seems like we don't support dispatch_now at all anymore sorry

SubrataM3 commented 2 years ago

@driesvints Yea, But can you tell me how I can use dispatchSync() in lumen? The guide here is pretty vague and the larvel documention does not work on lumen.

Call to undefined method App\Jobs\CreateUser::dispatchSync()

It seems laravel provides dispatchSync via Dispatchable trait which does not exist on lumen but that's present on laravel.

driesvints commented 2 years ago

I think it's best that you switch to Laravel if you need that, sorry.