From a61671c345367a90305ddb17ef6fb018ba7c9a3d Mon Sep 17 00:00:00 2001 From: Matt Conway Date: Thu, 16 Sep 2021 11:33:58 -0400 Subject: [PATCH] format template error message so cause is up front --- lib/kubetruth/template.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/kubetruth/template.rb b/lib/kubetruth/template.rb index 1ac1744..51d66e8 100644 --- a/lib/kubetruth/template.rb +++ b/lib/kubetruth/template.rb @@ -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, ""] }]) 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