Empty Errors are Printing Out

Permalink 1 user found helpful
My view.php file is outputting the code as if it is displaying an error, except there are no errors to display. Here is the html that outputs:

<ul class="ccm-error">
</ul>


And here is the section of my view.php file that should print errors if any exists:

<?php  if (isset($error) && $error != '') { ?>
   <?php  
   if ($error instanceof Exception) {
      $_error[] = $error->getMessage();
   } else if ($error instanceof ValidationErrorHelper) { 
      $_error = $error->getList();
   } else if (is_array($error)) {
      $_error = $error;
   } else if (is_string($error)) {
      $_error[] = $error;
   }
      ?>
      <ul class="ccm-error">
      <?php  foreach($_error as $e) { ?><li><?php echo $e?></li><?php  } ?>
      </ul>


I've been digging into this for days and can't figure out what's wrong. I do this the EXACT same way on every other site I build and non of them display the empty error tag.

Thoughts?

leinteractive
 
guythomas replied on at Permalink Reply
guythomas
so, obviously $ error is set, have you dove a vardump($error) right after your opening if statement?

You should also figure out which of the nested if statements is running by echo ing a little identifier in each of the potential cases. That would be a good start to your troubleshooting.
Guy
leinteractive replied on at Permalink Reply
leinteractive
What would vardump($error) accomplish?
guythomas replied on at Permalink Reply
guythomas
It would show you exactly what is in the $error array.
leinteractive replied on at Permalink Reply
leinteractive
Well I put vardump($error); after the opening IF statement, and now nothing shows up at all...just a blank content area.
leinteractive replied on at Permalink Reply
leinteractive
Also, tracing out each of the possible errors in the else/if series, turns out there is a ValidationError somewhere...
guythomas replied on at Permalink Reply
guythomas
Since it is a validation error the var dump will probably simply output the word object. Now that you know it is a validation error you can go and track down why your validation error checking is even being run. You may also want to place a var dump statement and expose exactly what is coming our of the $ error->getlist command.
guythomas replied on at Permalink Reply
guythomas
You need to view the page source to see the output of vardump.. You can use printr () if you want it rendered.
leinteractive replied on at Permalink Reply
leinteractive
I did check the page source...there was nothing at all in my content div where all of this code was placed.
leinteractive replied on at Permalink Reply
leinteractive
Alright...so print_r($error) gives me this:

ValidationErrorHelper Object ( [error:protected] => Array ( ) )

And tracing out getList returns just an empty array.

No idea what that means....or how to fix it!
guythomas replied on at Permalink Reply
guythomas
Why is validation checking even being performed. Do you only get this problem when you POST / GET something to this page, or does this happen when you first visit the page?

-Guy
leinteractive replied on at Permalink Reply
leinteractive
This is on every page the utilizes my view.php file (so the login page, profile page, all of the "Discussion" pages that come with the Discussion Forum addon).

I normally wouldn't even notice the empty error except I have the <ul class="error"> tag styled to have a red border around it, so it shows up all the time...but with nothing in it.

The error only shows up after a user is logged in. Visiting the login page for the first time works fine...after logging in I see this.
guythomas replied on at Permalink Reply
guythomas
Try replacing your code with this:

<?php  if (isset($error) && $error != '') { ?>
   <?php  
   if ($error instanceof Exception) {
      $_error[] = $error->getMessage();
   } else if ($error instanceof ValidationErrorHelper) { 
     if (!empty($error->getList())){
     $_error = $error->getList();
     }
   } else if (is_array($error)) {
      $_error = $error;
   } else if (is_string($error)) {
      $_error[] = $error;
   }
   if ($_error){
      ?>
leinteractive replied on at Permalink Reply
leinteractive
That actually breaks the page. Any page utilizing the view.php file is just white with no source code to view.
guythomas replied on at Permalink Reply
guythomas
I didn't test that code, so it must be invalid. Do you know why php isn't printing out any errors?
leinteractive replied on at Permalink Reply
leinteractive
Probably because I have the site set to Production instead of Development.
leinteractive replied on at Permalink Reply
leinteractive
So putting the site in Development mode spits out this when I use the code you gave me:

Fatal error: Can't use method return value in write context in /web/content/themes/greater-mn/view.php on line 94

Line 94 is this:

if (!empty($error->getList())){
guythomas replied on at Permalink Best Answer Reply
guythomas
Assign the getlist to a variable right above that line, then put the variable as the argument for the empty empty command. That should fix it.

Guy
leinteractive replied on at Permalink Reply
leinteractive
That did the trick! Thanks, guythomas! For anyone who runs into this in the future, here is the working view.php code that I'm using based on the above info:

<?php  if (isset($error) && $error != '') { ?>
   <?php  
   if ($error instanceof Exception) {
      $_error[] = $error->getMessage();
   } else if ($error instanceof ValidationErrorHelper) { 
    $listError = $error->getList();
    if (!empty($listError)){
     $_error = $error->getList();
     }
   } else if (is_array($error)) {
      $_error = $error;
   } else if (is_string($error)) {
      $_error[] = $error;
   }
   if ($_error){


Though I still have no idea why there would be empty errors in the first place!
guythomas replied on at Permalink Reply
guythomas
Yeah, it really is just a work around. Just make sure to do as much testing as you can to ensure that any actual errors are properly rendered. Especially validation errors like email addresses etc.

-Guy