Browse Source

Improve view errors.

Taylor Otwell 12 years ago
parent
commit
b043482905
2 changed files with 23 additions and 2 deletions
  1. 14 2
      laravel/error.php
  2. 9 0
      laravel/view.php

+ 14 - 2
laravel/error.php

@@ -15,6 +15,18 @@ class Error {
 
 		ob_get_level() and ob_end_clean();
 
+		$message = $exception->getMessage();
+
+		// For Laravel view errors we want to show a prettier error:
+		$file = $exception->getFile();
+
+		if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel/view.php'))
+		{
+			$message = 'Error rendering view: ['.View::$last['name'].']'.PHP_EOL.PHP_EOL.$message;
+
+			$file = View::$last['path'];
+		}
+
 		// If detailed errors are enabled, we'll just format the exception into
 		// a simple error message and display it on the screen. We don't use a
 		// View in case the problem is in the View class.
@@ -22,9 +34,9 @@ class Error {
 		{
 			echo "<html><h2>Unhandled Exception</h2>
 				  <h3>Message:</h3>
-				  <pre>".$exception->getMessage()."</pre>
+				  <pre>".$message."</pre>
 				  <h3>Location:</h3>
-				  <pre>".$exception->getFile()." on line ".$exception->getLine()."</pre>";
+				  <pre>".$file." on line ".$exception->getLine()."</pre>";
 
 			if ($trace)
 			{

+ 9 - 0
laravel/view.php

@@ -44,6 +44,13 @@ class View implements ArrayAccess {
 	 */
 	public static $cache = array();
 
+	/**
+	 * THe last view to be rendered.
+	 *
+	 * @var string
+	 */
+	public static $last;
+
 	/**
 	 * The Laravel view loader event name.
 	 *
@@ -387,6 +394,8 @@ class View implements ArrayAccess {
 	 */
 	protected function load()
 	{
+		static::$last = array('name' => $this->view, 'path' => $this->path);
+
 		if (isset(static::$cache[$this->path]))
 		{
 			return static::$cache[$this->path];