[Dancer-users] Supplied view (...) was not found

David Precious davidp at preshweb.co.uk
Tue Dec 27 19:21:58 CET 2011


On Tue, 27 Dec 2011 04:01:04 +0600
Nick Knutov <mail at knutov.com> wrote:

> Hi all,
> 
> I have strange bug and no ideas what to do with it.
> 
> Template engine: ctpp
> 
> my $mail = template 'mails/ticket_new.txt', $data, {layout=>undef};
> 
> [3150] error @5.768842> [hit #1]Supplied view (mails/ticket_new.txt)
> was not found.
> in /usr/local/share/perl/5.10.1/Dancer/Template/Abstract.pm l. 167
> [3150] error @6.503130> [hit #1]request to /reg/ crashed: 
> Dancer::Response=HASH(0xb3f0718) in 
> /usr/local/share/perl/5.10.1/Dancer/Handler.pm l. 98
> 
> kola at vbox:path/to/app/views$ ls -l mails/ticket_new.txt
> -rw-r--r-- 1 kola kola 339 2011-08-19 19:47 mails/ticket_new.txt

Looking at the relevant code in Dancer::Template::Abstract :

    if ($view) {
        # check if the requested view exists
        my $view_path = $engine->view($view);
        if (-e $view_path) {
            $content = $engine->apply_renderer($view, $tokens);
        } else {
            Dancer::Logger::error("Supplied view ($view) was not
            found.");

Since it's checking whether $view_path exists, it should really use
$view_path in the error message, not $view.

If it did, the problem would become more apparent - the view() method
appends the default template extension if the view name supplied
doesn't already end in it.

Dancer::Template::Ctpp2->default_tmpl_ext() will return 'ct2' if the
use_bytecode option is enabled, or 'tmpl' otherwise.

So, Dancer is looking for mails/ticket_new.txt.tmpl, not
mails/ticket_new.txt - but unfortunately, that error message is not
clear as to why.

I think there are two fixes here:

(a) make the error message clearer, so it's obvious what's going on;
(b) check for a view matching the exact name supplied first, before
attempting to add the default template extension; I think this would be
the most appropriate behaviour.

So, for the time being, renaming the template will make things work,
and I'll fix this oversight shortly - thanks for reporting it!

Cheers

Dave P

-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github


More information about the Dancer-users mailing list