Having a weird issue. I have a portal I have developed which up until today has been working good in both the prod and dev environments. Today after running a composer update everything works great on dev environment but when I pushed it to production one of my pages stopped working. The page allows me to pull up a user account and modify certain fields(pretty straight forward).
As an example/test I have created a test function in the controller to spit out a specific users information:
public function getTest(){
$user = Sentry::findUserByLogin('XXXXX');
echo $user;
}
When I run this function on the dev side it shows all the information its suppose to. When on the production side I get this error:
production.ERROR: 500 - Method Cartalyst\Sentry\Users\Eloquent\User::__toString() must not throw an exception # /employees/admin/test
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Method Cartalyst\Sentry\Users\Eloquent\User::__toString() must not throw an exception' in E:\sites\yaya.com\portal\app\src\employees\controllers\admin.php:0
Stack trace:
[internal function]: Illuminate\Exception\Handler->handleShutdown()
{main} [] []
I have not modified anything inside of Sentry or Eloquent.
Any ideas on what would cause this error? On the production side if I do a var_dump(user) it wont throw the error and I can see everything inside the protected fields. Or if I do echo $user->username it also works just fine. Problem is I need to return the user information as well as the groups the user is in to my JS to display it on my screen depending on the drop down selected for the user.
Finally figured it out! Not sure what happened but I started comparing rows of data in the database and found a few discrepancies. Pulled up the design view and sure enough a couple fields were different on production then my dev enviroment. Instead of "datetime" they were set to "smalldatetime" not sure what would have caused that but changed it to "datetime" and it all started working.
Thanks for the help Werewolf!
The most general case when this error is produced is mistype, when, f.e. instead of
{{ $user->id }}
Someone types
{{ $user }}
So error clearly says that method toString was called.
Related
How would i remove the lengthy stack trace errors that Laravel uses by default? (i understand it is using "Ignition")
Some resources that i've found that did not help:
this thread only mentions how to disable error reporting altogether
when i write anything in a render() method in the app/Exceptions/Handler.php like mentioned here i only get error 500 without any output.
person in this thread even suggests writing your own Laravel bootstrap application instead of using the default one, breaking Laravel framework semantics, but that's just plain mad.
I have also tried looking at configuration values for Ignition by publishing ignition config file via
php artisan vendor:publish --provider="Facade\Ignition\IgnitionServiceProvider" --tag="ignition-config"
But that file has nothing to configure, the only thing you can do is to hide the "share" message in the error.
I just want a simple classic php error page with file/line/error, no stack traces, or no html markup. The error page makes it really difficult to debug output in anything else than a web browser.
Simply override the render() method in your app's exception handler. Per comments in the base class, this method must return a response object.
public function render($request, \Throwable $e)
{
return response()->view("exception", ["exception" => $e]);
}
Then make your blade view look however you want.
<!doctype html>
<title>Exception</title>
<body>
<p>
Exception of type <code>{{ get_class($exception) }}</code>
thrown in <code>{{ $exception->getFile() }}</code>
on line <code>{{ $exception->getLine() }}</code>.
</p>
</body>
i have a proyect in production made with Laravel 5.4 on AWS, with EC2 and RDS (with autoscaling).
In a normal day our current configuration doesn't have a problem handling a certain amount of users, but sometimes this number of user grows up enough to start generating this DB Max Connections error [1040], even tho we have autoscaling configured to avoid this (i think that the replica is taking enough time to start while we still have some users trying to access).
So, in the Handler.php file we put this code to show a custom page informing the issue to the user (and not just the generic woops!)
if ($e instanceof \PDOException) {
Log::error('Data Base Exception');
$errCode = $e->getCode();
switch ($errCode) {
case 1040:
return response()->view("errors.database", []);
break;
default:
return response()->view("errors.500", [], 500);
break;
}
}
The problem is that apparently laravel is opening more than 1 connection at the same time even this is only a single GET request (it happens to any request on the proyect), so the Handler.php is reporting it twice. Here is a look at the log file generated when throwing this exception.
[2018-10-11 14:04:09] production.ERROR: Data Base Exception
[2018-10-11 14:04:09] production.ERROR: Data Base Exception
I have tested this on my local enviroment, setting the max_connections attribute from mysql to 1
set global max_connections = 1;
This throws the exception as intented, but the HTML page with the information of the problem appears also twice, just like the log.
html with error to the user
Curious thing: when i set the max_connections atributte to 2, the exception is not throwed and laravel process the request normally.
EDIT: it works in this case because i didn't considered that i was using DBeaver to access the database. But the problem of throwing the exception twice persist
The question is: what is laravel doing that need 2 conections even when is just 1 user trying to access? Or maybe this is something related with some kind of reconnection attempt?
I posting this here because, although I have already found a solution, it might be worth to know whether some other people has faced the same problem and can provide a better explanation for this. The issue is as follows:
A function receives an array as parameter, and depending of the content of a given key-value pair, does one action or another:
if ($info['password'] != "") {
// action 1
}else{
// action 2
}
It also returns the value of this key at the end:
return array("user" => $user, "pwd" => $info['password']);
Therefore, if $info['password'] is not set, it should return this error:
ContextErrorException. Undefined index: password
This happens when I run my application locally in development mode, using app/console server:run, but it gets masked when deploying in production server or also when running server:run --env=prod: It simply does not show any error nor warning. Is this an expected behaviour?
Has this something to do with Symfony configuration or is it a php.ini related issue?
It makes sense from a practical point of view, the application returns an empty field but it does not crash and the user does not realize of the bug, but it might be very bad when trying to debug the application.
I need to couple my application with its database. To do this, I've generated an entity with doctrine:generate:entity. It's produced an entity with appropriate annotations for mapping. I've also used doctrine:schema:update --force to actually create the schema on the database server, which I can confirm it has done with phpMyAdmin.
In my controller I'm trying to simply insert a row like so:
public function testAction() {
$file = new File();
$file->setTest('A Foo Bar');
$em = $this->getDoctrine()->getManager();
$em->persist($file);
$em->flush();
return new JsonResponse(array('foo' => 'bar'));
}
The entity only has one field called test which is string and of length 255. When I request this URL through an AJAX request in my application, it throws back a very uninformative 500 Internal Server Error:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please e-mail us at [email] and let us know what you were doing when this error occurred. We will fix it as soon
as possible. Sorry for any inconvenience caused.
The PHP error logs also don't have any error information. This controller action does work if I remove the database manipulation stuff. The application is also running in the dev environment.
Is there any way I can get a more descriptive error message to at least tell me what's wrong?
This is a default error page that you get in production. You can customize it - http://symfony.com/doc/current/cookbook/controller/error_pages.html
You can catch and read an error creating ExceptionListener - http://symfony.com/doc/current/cookbook/event_dispatcher/event_listener.html
Also you can switch to dev environment to show error text and log.
If you just want dev logs but prod environment, you can copy contents of monolog section app/config/config_dev.yml to app/config/config_prod.yml.
If anyone here comes across this issue and is lost, the cause in my case was that I had specified a new #ORM\ManyToOne relationship and was persisting instead of merging the entity.
This in the past has returned a valid error, but in this case the php script was not handling it at all.
I am creating a Symfony2 application, all works well, but when i try to execute my behat tests or clear the cache, i got this error:
Error: Call to undefined method
Symfony\Bundle\FrameworkBundle\Templating\Loader\TemplateLocator::isFresh() in
[...]/vendor/symfony/assetic-
bundle/Symfony/Bundle/AsseticBundle/Factory/Resource/FileResource.php line 49
TemplateLocator does not even implements LoaderInterface, as required in FileResource construct.
Anyone has a clue ?
I figured out where the problem came from, but without understanding it.
It appeared that somewhere in my application I called
$this->container->get('twig')->render("Bundle:View:action.html.twig")
I changed to
$this->container->get('templating')->render("Bundle:View:action.html.twig")
twig service is a Twig_Environment instance, and template is a DelegatingEngine instance, both allowing to render a template.
And all works great again.
If someone could explain me what happened, I'll appreciate :)