Skip to content

Commit

Permalink
catch more error types when rendering template to make it obvious the…
Browse files Browse the repository at this point in the history
… error is in a template
  • Loading branch information
wr0ngway committed Sep 24, 2021
1 parent 74c3cc6 commit 9036e07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/kubetruth/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def render(*args, **kwargs)

result

rescue Liquid::Error => e
rescue StandardError => e
msg = "Template failed to render with error message:\n"
msg << (INDENT * 2) << e.message << "\n"
if e.is_a?(Liquid::UndefinedVariable)
Expand Down
2 changes: 2 additions & 0 deletions spec/kubetruth/template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ module Kubetruth

it "fails fast" do
expect { described_class.new("{{foo") }.to raise_error(Kubetruth::Template::Error)
expect { described_class.new("{{+}}").render }.to raise_error(Kubetruth::Template::Error)
expect { described_class.new("{{foo}}").render }.to raise_error(Kubetruth::Template::Error)
expect { described_class.new("{{foo | nofilter}}").render(foo: "bar") }.to raise_error(Kubetruth::Template::Error)
expect { described_class.new("{{foo | nindent: 2}}").render(foo: 5.5) }.to raise_error(Kubetruth::Template::Error)
end

it "does procs" do
Expand Down

0 comments on commit 9036e07

Please sign in to comment.