Lumen shows blank page instead of showing an error on blade - php

I came across with interesting problem,
I am using lumen on my windows localhost, the problem is while I write incorrect code or syntax error in my view/blade, lumen shows blank page instead of error. However, in controller or another page I am able to debug my code, It shows error.
Error debugging is open in php.ini.
APP_DEBUG=true in my project.
I have tried to fresh install, still same.

Edit app/Exceptions/Handler.php file , method render
e.g. make something like this:
public function render($request, Throwable $exception)
{
if (env('APP_DEBUG')) {
dd($exception);
}
return parent::render($request, $exception);
}
or you can grab it as it is instanceof Illuminate\View\ViewException

Related

how to send error emails to the developer in laravel 8 App

I am using laravel "laravel/framework": "^8.75" version.
When deployed the app turn APP_DEBUG=false but users get errors but they can not know what is wrong and me to I don't know because I tested it but my trial go through without an error.
I need to receive an email of any error exceptions that are thrown on the app in details like APP_DEBUG=true.
All the solutions I have found are of other versions whose App\Exceptions\Handler is having report() and render() classes yet here I have
public function register(){
$this->reportable(function (Throwable $e) {
//
});
}

How to use Errbit in Laravel 4?

I just install the Errbit in my PC using ruby, and it's already running on my local. And I developed a web apps using Laravel 4, but I didn't know how can I send all of the errors of my web apps to the errbit.I already installed this package, but I didn't know how to implement this on my web apps.
I already tried to use below script on my ../app/start/global.php on Applicatoin Error Handler, but it's only show me the white page. This is my script:
<?php
...
App::error(function(Exception $exception, $code)
{
Errbit::instance()->notify($exception);
Log::error($exception);
});
...
And this is how I create an error in my controller, I remove the semicolon delimeter like this:
<?php
class someController extends \BaseController {
public function index(){
return View::make('editor.index') //Remove ';' at the end of line code
}
}
If I remove the errbit instance Errbit::instance()->notify($exception); on global.php, the page will return Whoops error from laravel, but if I add errbit instance, it's only show the blank white page, and nothing happend to the errbit report.
And also I already tried to put the errbit on the method of controller like below, but I still get nothing.
<?php
public function index(){
try {
return View::make('editor.index')
} catch (Exception $e) {
Errbit::instance()->notify($e);
}
}
Please help me, and thanks before.

Laravel 5 blade shows a blank page when there is error instead of throwing exception

In laravel 4 when you try to render a view that does not exists in app\views or a view with undefined variables laravel will throw an exception or show error that helps with debug.
I have a fresh installation of laravel 5.0.13 and am having a tough time troubleshooting a blade template that shows a blank page when i render a view that does not exists instead or a template with undefined variables instead of throwing an exception or error which will clue me in when debug.
I have installed filp/whoops:~1.0. but still recieve a blank page
class ProfileController extends Controller
{
public function index()
{
return view('indexx'); //this view does not really exist
}
}
The file indexx does not exist in my resources/views and i expect Laravel to throw an exception but am getting a blank page instead, why?
Also when i render a view that exists with some undefined variables i simply get a blank page
Example:
class ProfileController extends Controller
{
public function index()
{
return view('index'); //this view exists
}
}
The content of resources/views/index
{!! $this_variable_was_not_passed_an_I_expect_error !!}
As you can see in the view file above the variable does not exist by laravel will simply show a blank page instead of throwing an exception or some debug error.
Also to note i change my laravel default view in config/views
'paths' => [
//realpath(base_path('resources/views'))
realpath(base_path('resources/themes/default'))
],
And laravel was able to render views from resources/themes/default as long as there is no error in the template however, if any error was encountered such ar undefined variable a laravel displays a blank page instead of showing error message
Also to mention that I install virtual box and vagrant on window 7
Could this be a bug or something? Please assist.
Try to change permission on the storage folder:
chmod -R 0777 storage
It worked for me.
I don't really know why this happened but its now working as required after i run
vagrant destroy to destroy homestead VM
and then vagrant up - to create the VM
The error messages has now showing up instead of blank page:
An alternative solution which helped me, is running
composer install
I deployed with git which auto ignores some files. running composer install fixed it for me.
I got the same problem but here comes the reason and the solution:
The logfiles in storage/logs needs to be owned/writable by the webserver user. Otherwise L5 gives you a blank page.
I run "php artisan ..." always as root. If an exception was thrown and Laravel creates a new logfile, then it's owned by root. On my Debian i run in the project root folder:
chown www-data.root * -R
to solve this problem.
//lavarel 4
* Add this to app/start/gobal.php
App::error(function(Exception $e, $code) {
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
return $handler->handle($e);
});
//lavarel 5
* Add this to app/Exceptions/Handler.php
public function render($request, Exception $exception)
{
..........
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
$handler->handle($e);
......
return parent::render($request, $e);
}

Laravel 4 always returns HTTP status code 200

I have below code in error.php, which is triggered using App::abort(404, $error) in my controller. Still my response status code is 200(ok). I tried with various error codes like 400, 403
// NotFoundException handler
App::error(function(NotFoundException $e)
{
$default_message = 'The requested resource was not found';
return Response::json(array(
'error' => $e->getMessage() ?: $default_message,
), 404);
});
For anyone still googling this problem:
I was struggling with this problem for hours. For me the problem was caused by an issue with one of my controllers.
Check all of your controllers and make sure there are no spaces in front of the <?php tag. The <?php tag should be the very first thing in the file. A single space in front of the <?php tag in any of your controllers that are routed as such:
Route::controller('example', 'ExampleController');
Will cause all status codes to be 200.
I believe, regardless, you should receive a 404 response, so there might be something else happening that's the result of code not included in your question.
That being said, the Exception class that is thrown for 404 is NotFoundHttpException rather than NotFoundException.
Since Laravel 4 uses Symfony's HttpKernal, that Exception is here.
You can see here where App::abort() throws NotFoundHttpException when a 404 is triggered.
Therefore, your code should look like:
// NotFoundHttpException handler
App::error(function(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)
{
$default_message = 'The requested resource was not found';
return Response::json(array(
'error' => $e->getMessage() ?: $default_message,
), 404);
});
Important: This will only fire for a 404 status, as that's the corresponding code to NotFoundHttpException. Other status codes return other Exception classes. To capture all HTTP status error codes exceptions, type hint for HttpException like so:
// HttpException handler
App::error(function(\Symfony\Component\HttpKernel\Exception\HttpException $e)
{
return Response::json(array(
'error' => $e->getMessage(),
), $e-> getStatusCode());
});
Lastly, consider using a bit of Content Negotiation when deciding to return JSON or HTML.
The solution didn't worked for me, so in case anyone is still looking for an answer, I thought it be best to put it here instead of creating another question.
After some time I had this problem too, in my app/Exceptions/Handler.php I had:
if ($e instanceof ModelNotFoundException) {
if ($request->ajax()) {
return response()
->json(['error' => ['No results']])
->header('status', 422);
}
}
This worked in my local environment, however, in the homolog environment (which reproduces the production environment, just to be clear) it didn't returned the correct status code.
After another look I started looking at Laravel's docs, and I changed the call to the following:
return response()
->json(['error' => ['No results.']], 422);
And that did the trick. Hope this can help.
In my case I found some space in front of <?php
Remove dump & other print functions
I was actively debugging when I noticed this issue. It was caused because I had dump(...) calls in the code at that time.
When I removed all my debug dump calls, the status code was correctly 404 again (using abort(404).

Kohana 404 custom page

I have been looking around and following each tutorials,there is one which stands out. http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/ <-- i followed this tutorial and everything went smoothly
the error is being detected
the exception is being handled
but there has been an exception that i cant seem to find. im currently having this exception
Fatal error: Exception thrown without a stack frame in Unknown on line 0
all of my codes are thesame to the site-link. please help me.. im bugging around for this since ever, i've looked through here also Kohana 3 - redirect to 404 page but since im a beginner, its really hard understanding it. I've also found out that there is a major revamp from KO 3.0 to 3.1 how about KO 3.2? Thank you for your help guys :)
From the kohana source-code.
- > If you receive *Fatal error: Exception thrown without a stack frame in Unknown on line 0*, it means there was an error within your exception handler. If using the example above, be sure *404.php* exists under */application/views/error/*.
Maybe it helps. This probably has been fixed, but I'm not following the kohana development that much. It's related to pull request #246: https://github.com/kohana/core/pull/246 and this is the source: https://github.com/kohana/core/pull/246/files#L208L76
here is how I do it with Kohana 3.2
Add exceptions handling stuff in index.php
try
{
$request = $request->execute();
}
catch(Kohana_HTTP_Exception_404 $e)
{
$request = Request::factory('errors/404')->execute();
}
catch(Exception $e)
{
$request = Request::factory('errors/500')->execute();
}
echo $request->send_headers()->body();
Then write Errors controller
class Controller_Errors extends Controller
{
public function __construct($request, $response)
{
parent::__construct($request, $response);
}
public function action_404()
{
$this->response->body(View::factory('errors/404'));
}
public function action_500()
{
$this->response->body(View::factory('errors/500'));
}
}
Create 2 corresponding error pages (404.php and 500.php in views/errors)
Add new route to your bootstrap.php or use default one (depends on you project's structure), just make sure Controller_Errors can be reached when exception is thrown
Now every time you throws the exception in your controller, it will display the custom error page, like this
throw new HTTP_Exception_404;

Categories