Enhance Error Reporting
mgerzabek opened this issue · 4 comments
Hi @27pchrisl,
In the meantime I have a small service running with your exceptional lodata package and so far everything is fine. Thank you for this great piece of software!
One thing that could be enhanced is the error reporting. The stacktrace for actual errors is not really helpful. This is one taken from my production environment.
[2024-03-20 13:35:53] production.ERROR: Undefined array key 0 {"userId":9,"exception":"[object] (Flat3\\Lodata\\Exception\\Protocol\\InternalServerErrorException(code: 0): Undefined array key 0 at /home/forge/timesheet.biz/vendor/flat3/lodata/src/Controller/Transaction.php:1274)
[stacktrace]
#0 /home/forge/timesheet.biz/vendor/flat3/lodata/src/Controller/OData.php(32): Flat3\\Lodata\\Controller\\Transaction->execute()
#1 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Flat3\\Lodata\\Controller\\OData->handle()
#2 /home/forge/timesheet.biz/vendor/flat3/lodata/src/Controller/OData.php(42): Illuminate\\Routing\\Controller->callAction()
#3 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(43): Flat3\\Lodata\\Controller\\OData->callAction()
#4 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Route.php(259): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#5 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\\Routing\\Route->runController()
#6 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(806): Illuminate\\Routing\\Route->run()
#7 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#8 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(57): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#9 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Auth\\Middleware\\Authenticate->handle()
#10 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#11 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(805): Illuminate\\Pipeline\\Pipeline->then()
#12 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(784): Illuminate\\Routing\\Router->runRouteWithinStack()
#13 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(748): Illuminate\\Routing\\Router->runRoute()
#14 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Routing/Router.php(737): Illuminate\\Routing\\Router->dispatchToRoute()
#15 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(200): Illuminate\\Routing\\Router->dispatch()
#16 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(144): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#17 /home/forge/timesheet.biz/vendor/laravel/nova/src/Http/Middleware/ServeNova.php(23): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#18 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Laravel\\Nova\\Http\\Middleware\\ServeNova->handle()
#19 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#20 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#21 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ConvertEmptyStringsToNull->handle()
#22 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#23 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#24 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\TrimStrings->handle()
#25 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#26 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#27 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(99): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Foundation\\Http\\Middleware\\PreventRequestsDuringMaintenance->handle()
#29 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php(62): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#30 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\HandleCors->handle()
#31 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#32 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(183): Illuminate\\Http\\Middleware\\TrustProxies->handle()
#33 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(119): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(175): Illuminate\\Pipeline\\Pipeline->then()
#35 /home/forge/timesheet.biz/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(144): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#36 /home/forge/timesheet.biz/public/index.php(51): Illuminate\\Foundation\\Http\\Kernel->handle()
#37 {main}
"}
Since this error arose from a real world user, I can find no clue, where the error happens from reading the log file alone. I can second guess from the feeback I got from users. But that directs me into a wider area than maybe neccessary.
Anyway, in a prefect world I would see in the log file the odata request URI or if it is a $batch
request the individual request URI that led to the issue. With that additional information I could immediately understand where to look at and things would work out much easier in fixing issues that arise in production mode.
Hmm, yes. The exception you're actually interested in is nested within the InternalServerErrorException
. You might need some sort of custom error handler that checks whether the exception is an instanceof ProtocolException
and in that case report $e->getOriginalException()
instead of $e
. I'm not immediately sure if a package can change how the standard exception handler works...
Actually scratch that, it turns out all you have to do is add this to the exception itself:
public function getInnerException(): ?Throwable
{
return $this->originalException;
}
That's going through testing now...
This should work much better in https://github.com/flat3/lodata/releases/tag/v5.33.1
@27pchrisl
You are awesome man!
Thank you, I will test this tomorrow.