Skip to content

Improved the error message when a template is not found #17434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 3, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed the problem in an easier way
  • Loading branch information
javiereguiluz committed Jan 27, 2016
commit 88b913b0c465dd805d679a0642aba4fd17a20241
10 changes: 2 additions & 8 deletions src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected function findTemplate($template, $throw = true)
$file = parent::findTemplate($logicalName);
} catch (\Twig_Error_Loader $e) {
$previous = $e;
$errorMessage = $e->getMessage();

// for BC
try {
Expand All @@ -89,14 +90,7 @@ protected function findTemplate($template, $throw = true)
}

if (false === $file || null === $file) {
try {
list($namespace, $name) = $this->parseName($logicalName);
$paths = sprintf(' (looked into: %s)', implode(', ', $this->getPaths($namespace)));
} catch (\Twig_Error_Loader $e) {
$paths = '';
}

throw new \Twig_Error_Loader(sprintf('Unable to find template "%s"%s.', $name, $paths, -1, null, $previous));
throw new \Twig_Error_Loader($errorMessage, -1, null, $previous);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, why not just rethrow the previous exception if it is a Twig_Error_loader exception? throw $previous would do the same, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that there are two $previous. The first one is "the good one" ... but we always override it. If I use throw $previous the error message is worse:

worse_error_message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. Instead of storing $errorMessage = $e->getMessage();, why not store the exception itself and throw it here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. I tried to maintain the existing code ... but it doesn't make sense. Updated. Thanks!

}

return $this->cache[$logicalName] = $file;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy