Skip to content

Commit

Permalink
format template error message so cause is up front
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Sep 16, 2021
1 parent 1eee1f6 commit a61671c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/kubetruth/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,15 @@ def render(*args, **kwargs)
result

rescue Liquid::Error => e
msg = "Template failed to render:\n"
@source.lines.each {|l| msg << (INDENT * 2) << l }
msg << "\n" << INDENT << "with error message:\n" << (INDENT * 2) << "#{e.message}"
msg = "Template failed to render with error message:\n"
msg << (INDENT * 2) << e.message << "\n"
if e.is_a?(Liquid::UndefinedVariable)
msg << "\n" << INDENT << "and variable context:\n"
msg << INDENT << "and variable context:\n"
debug_kwargs ||= kwargs.merge(secrets: Hash[secrets.collect {|k, v| [k, "<masked:#{k}>"] }])
debug_kwargs.deep_stringify_keys.to_yaml.lines.collect {|l| msg << (INDENT * 2) << l }
end
msg << INDENT << "and template source:\n"
@source.lines.each {|l| msg << (INDENT * 2) << l }
raise Error, msg
end
end
Expand Down

0 comments on commit a61671c

Please sign in to comment.