Jump to content
MakeWebGames

Improved stack trace


a_bertrand

Recommended Posts

The current stack trace / error handling is let's say less than user friendly. Therefore (and under suggestion of Vienna) I modified it:

Replace the function handle_error in libs/common.php

/**
* Handles errors of the engine or the modules
*
* @param $errorMessage string           
* @param $filename string           
* @param $lineNumber integer           
* @param $stack array
*            stack trace
*/
function handle_error ($errorMessage, $filename, $lineNumber, $stack)
{
   global $content, $template, $isAdmin, $alwaysShowErrorDetails, $modules, $baseDir, $isSuperUser;

   ob_get_clean();
   ob_start();

   $template = "error";

   $filename = str_replace("\\", "/", $filename);

   // Admin show the full info
   if ($alwaysShowErrorDetails == TRUE || ($isAdmin && GetConfigValue("adminViewException", "bug_tracking") != "no"))
   {
       echo "Error: $errorMessage<br>";
       // Works only for super user, it shows the link to the code editor if
       // the module exists.
       if (isset($isSuperUser) && $isSuperUser == true && in_array("admin_code_editor", $modules) && strncmp(substr($filename, strlen($baseDir) + 1), "modules/", 8) == 0)
           echo "Error in file <a href='" . Secure("index.php?p=admin_code_editor&f=" . urlencode(substr($filename, strlen($baseDir . "/modules/"))) . "&l=$lineNumber", true) . "'>\"$filename\" on line $lineNumber</a><br>";
       else
           echo "Error in file \"$filename\" on line $lineNumber<br>";

       array_shift($stack);
       foreach($stack as $s)
       {
           echo "Error in {$s['file']}<br>";
           echo "Line {$s['line']}<br>";
       }
       echo "<br>";
   }

   echo Translate("Please help us to improve the game by providing as much information regards any bugs.");
   echo "</span><br> <br>";
   echo "<form method='post' name='reportBug'>";
   echo "<input type='hidden' name='action' value='reportBug'>";
   TableHeader("Step by step how to reproduce it:");
   echo "<textarea name='report'></textarea><br>";
   TableFooter();
   echo "</form>";
   ButtonArea();
   SubmitButton("Report", "reportBug");
   LinkButton("Back", "index.php");
   EndButtonArea();

   $_SESSION["bug_line"] = $lineNumber;
   $_SESSION["bug_file"] = $filename;
   $_SESSION["bug_report"] = "Error: $errorMessage\nError in file \"$filename\" on line $lineNumber\n" . print_r($stack, true);

   $content['main'] = ob_get_clean();
   // Clean the output to avoid double content
   error_reporting(0);
   ShowTemplate();
   exit();
}

 

This fix will be included in the next release.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...