Permalink
Browse files

[agent] Fix bind_configuration error message

If there is an error when binding a template, return the correct
template line error.

Change-Id: I61a4360fe28eea78dc720e584c8877d7a96f4e79
  • Loading branch information...
frodenas committed Dec 31, 2012
1 parent 572c1cf commit c4cb6cd92678b9b91da4fc87ad69d70123c9f0dd
Showing with 26 additions and 1 deletion.
  1. +3 −1 agent/lib/agent/apply_plan/job.rb
  2. +23 −0 agent/spec/unit/apply_plan/job_spec.rb
@@ -113,12 +113,14 @@ def bind_configuration
end
template = ERB.new(File.read(template_path))
+ template.filename = src
begin
result = template.result(@config_binding)
rescue Exception => e
# We are essentially running an arbitrary code,
# hence such a generic rescue clause
- line = e.backtrace.first.match(/:(\d+):/).captures.first
+ line_index = e.backtrace.index{ |l| l.include?(src) } || [0]
+ line = e.backtrace[line_index].match(/:(\d+):/).captures.first
install_failed("failed to process configuration template " +
"'#{src}': " +
"line #{line}, error: #{e.message}")
@@ -264,6 +264,29 @@ def template_for(job)
"'foo.erb': line 1, error: undefined method " +
"`bar' for nil:NilClass")
end
+
+ it "fails if property cannot be found" do
+ manifest = {
+ "templates" => {
+ "foo.erb" => "config/foo"
+ }
+ }
+
+ template_for(job) do |template|
+ template.add_file("job.MF", YAML.dump(manifest))
+ template.add_file("templates/foo.erb", "<%= p('foo.bar') %>")
+ end
+
+ manifest_path = File.join(job.install_path, "job.MF")
+
+ expect {
+ job.install
+ }.to raise_error(Bosh::Agent::ApplyPlan::Job::InstallationError,
+ "Failed to install job 'ccdb.postgres': " +
+ "failed to process configuration template " +
+ "'foo.erb': line 1, error: Can't find property " +
+ "`[\"foo.bar\"]'")
+ end
end
end

0 comments on commit c4cb6cd

Please sign in to comment.