From 07ff4be92a1d46fe0f6ec3de3c33b5a3b99be755 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Sun, 17 May 2009 23:08:40 -0500 Subject: Fixing #2250 - Missing templates throw a helpful error This changes the behaviour of template searching a bit - we previously usually returned a file name, whether the template existed or not. Now we only return a path if it exists. Refactoring a few of the the tests for TemplateWrapper, also. Signed-off-by: Luke Kanies --- lib/puppet/parser/files.rb | 10 +++++----- lib/puppet/parser/templatewrapper.rb | 7 ++----- 2 files changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index ca4fb4f10..749428e9f 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -41,7 +41,7 @@ module Puppet::Parser::Files if template_paths = templatepath(environment) # If we can find the template in :templatedir, we return that. - td_file = template_paths.collect { |path| + template_paths.collect { |path| File::join(path, template) }.each do |f| return f if FileTest.exist?(f) @@ -49,11 +49,11 @@ module Puppet::Parser::Files end # check in the default template dir, if there is one - unless td_file = find_template_in_module(template, environment) - raise Puppet::Error, "No valid template directory found, please check templatedir settings" if template_paths.nil? - td_file = File::join(template_paths.first, template) + if td_file = find_template_in_module(template, environment) + return td_file end - td_file + + return nil end def find_template_in_module(template, environment = nil) diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 8b333a0b6..00faf33a1 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -65,11 +65,8 @@ class Puppet::Parser::TemplateWrapper end def file=(filename) - @file = Puppet::Parser::Files.find_template(filename, scope.compiler.environment) - - unless FileTest.exists?(file) - raise Puppet::ParseError, - "Could not find template %s" % file + unless @file = Puppet::Parser::Files.find_template(filename, scope.compiler.environment) + raise Puppet::ParseError, "Could not find template '%s'" % filename end # We'll only ever not have a parser in testing, but, eh. -- cgit