summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-05-17 23:08:40 -0500
committerJames Turnbull <james@lovedthanlost.net>2009-05-18 17:05:26 +1000
commit07ff4be92a1d46fe0f6ec3de3c33b5a3b99be755 (patch)
treeb6337cf6ee22b7e0ace0d1b3a635f1fdacd5fd68 /lib/puppet/parser
parent7ce42daf5a0c2e3946732f7acb1c0ce680dc432e (diff)
downloadpuppet-07ff4be92a1d46fe0f6ec3de3c33b5a3b99be755.tar.gz
puppet-07ff4be92a1d46fe0f6ec3de3c33b5a3b99be755.tar.xz
puppet-07ff4be92a1d46fe0f6ec3de3c33b5a3b99be755.zip
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 <luke@madstop.com>
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r--lib/puppet/parser/files.rb10
-rw-r--r--lib/puppet/parser/templatewrapper.rb7
2 files changed, 7 insertions, 10 deletions
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.