{"record":{"id":"0e6a7b264efdf43c","repo":"puppetlabs/puppet","slug":"template-file-does-not-exist","errorCode":null,"errorMessage":"Template %{file} does not exist","messagePattern":"Template %(.+?) does not exist","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/resource_template.rb","lineNumber":49,"sourceCode":"#\n#   <%= @name %>\n#\n# Since the ResourceTemplate class sets as instance variables all of the resource's\n# parameters.\n#\n# Note that this example uses the generating resource as its source of\n# parameters, which is generally most useful, since it allows you to configure\n# the generated resource via the generating resource.\nclass Puppet::Util::ResourceTemplate\n  include Puppet::Util::Logging\n\n  def evaluate\n    set_resource_variables\n    Puppet::Util.create_erb(Puppet::FileSystem.read(@file, :encoding => 'utf-8')).result(binding)\n  end\n\n  def initialize(file, resource)\n    raise ArgumentError, _(\"Template %{file} does not exist\") % { file: file } unless Puppet::FileSystem.exist?(file)\n\n    @file = file\n    @resource = resource\n  end\n\n  private\n\n  def set_resource_variables\n    @resource.to_hash.each do |param, value|\n      var = \"@#{param}\"\n      instance_variable_set(var, value)\n    end\n  end\nend\n","sourceCodeStart":31,"sourceCodeEnd":64,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/resource_template.rb#L31-L64","documentation":"Puppet::Util::ResourceTemplate.new (resource_template.rb:49) raises ArgumentError when Puppet::FileSystem.exist?(file) is false. The path must be a concrete, readable filesystem path at construction time (a template path in a generated-resource workflow); no puppet:// URL resolution or module path lookup happens here, and evaluate() later reads the same path with UTF-8 encoding.","triggerScenarios":"ResourceTemplate.new('/etc/puppet/templates/foo.erb', resource) where the file was never created; a path built with an unexpanded variable ('#{modulename}/templates/foo.erb' inside single quotes in Ruby DSL, so the literal '#{' is checked); a relative path resolved against the process cwd instead of the module.","commonSituations":"Defined types/templates shipped without installing the module on the target node; case-sensitivity mismatches on macOS/Linux (Foo.erb vs foo.erb); moving module directories without updating absolute paths; file present but path string has a typo or trailing whitespace.","solutions":["Verify the exact path with Puppet::FileSystem.exist?(path) before constructing and fail with your own descriptive message.","Build template paths from fully-resolved module paths (Puppet::Module#template_path or File.join(module_dir, 'templates', name)) instead of string interpolation.","Check the file actually shipped: inspect the module packaging; re-install the module on the node.","Rescue ArgumentError at the construction site to add context (resource reference) before re-raising."],"exampleFix":"// before\ntpl = Puppet::Util::ResourceTemplate.new(\"#{mod}/templates/app.erb\", res) # mod nil inside single-quoted source\n\n// after\npath = File.expand_path(File.join(module_dir, 'templates', 'app.erb'))\nraise ArgumentError, \"template #{path} missing (module not installed?)\" unless Puppet::FileSystem.exist?(path)\ntpl = Puppet::Util::ResourceTemplate.new(path, res)","handlingStrategy":"validation","validationCode":"raise ArgumentError, \"template #{path} not found\" unless Puppet::FileSystem.exist?(path)\ntpl = Puppet::Util::ResourceTemplate.new(path, resource)","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Util::ResourceTemplate.new(path, resource).evaluate\nrescue ArgumentError => e\n  raise if e.message !~ /does not exist/\n  Puppet.err(\"missing template #{path} for #{resource.ref}\")\n  nil\nend","preventionTips":["Build template paths from the module's real location, never from string interpolation that can stay literal.","Assert template existence in module smoke tests on a target-like platform (case-sensitive FS)."],"tags":["puppet","template","erb","filesystem","argumenterror","missing-file"],"backgroundTag":"missing-template-file","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}