From b043482905b4d53b393943e851b288f904db9840 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 26 Sep 2012 16:20:56 -0400 Subject: [PATCH] Improve view errors. --- laravel/error.php | 16 ++++++++++++++-- laravel/view.php | 9 +++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/laravel/error.php b/laravel/error.php index 6b75d210..a53d2e0b 100644 --- a/laravel/error.php +++ b/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 "

Unhandled Exception

Message:

-
".$exception->getMessage()."
+
".$message."

Location:

-
".$exception->getFile()." on line ".$exception->getLine()."
"; +
".$file." on line ".$exception->getLine()."
"; if ($trace) { diff --git a/laravel/view.php b/laravel/view.php index d2544d24..5ac37520 100644 --- a/laravel/view.php +++ b/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];