Skip to content

Commit

Permalink
Made more error messages verbose.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikogan committed Jun 13, 2019
1 parent 9397e4f commit a0ed0df
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions j2tmpl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
class PermissiveUndefined(Undefined):
"""
A more permissive undefined that also also allows
__getattr__. This allows `default`to work across
__getattr__. This allows `default` to work across
the entire complex object.
"""
def __getattr__(self, name):
Expand All @@ -69,6 +69,9 @@ def read_file_filter(filename):
Jinja filter that reads the contents of a file into the template
given the filename.
"""
if isinstance(filename, Undefined):
return filename

with open(filename) as f:
return f.read()

Expand All @@ -82,6 +85,9 @@ def boolean_filter(value):
Note that this is case insensitive.
"""
if isinstance(value, Undefined):
return value

return str(value).lower() in ['true', 'yes', '1']


Expand Down Expand Up @@ -279,9 +285,6 @@ def main(argv): # pragma: no cover
render(args.template, args.output, build_template_context(os.environ), args)
except TemplateSyntaxError:
sys.exit(1)
except Exception:
print(str(sys.exc_info()[1]), file=sys.stderr)
sys.exit(1)


if __name__ == "__main__": # pragma: no cover
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

setup(
name="j2tmpl",
version="0.0.7",
version="0.0.8",
author="Ilya Kogan",
author_email="[email protected]",
url="https://github.com/ikogan/j2tmpl",
Expand Down
2 changes: 2 additions & 0 deletions tests/templates/filters/boolean.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
{% if test.boolean.no|boolean %}bad{% else %}cool{% endif %}

{% if test.boolean.zero|boolean %}bad{% else %}cool{% endif %}

{% if test.boolean.undefined|boolean %}bad{% else %}cool{% endif %}
1 change: 0 additions & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def test_error(common_environment, capsys):


def test_single_line_error(common_environment, capsys):

tmpfile = NamedTemporaryFile()
templateFile = os.path.join(TEST_TEMPLATE_PATH, "single-line-error.jinja")

Expand Down

0 comments on commit a0ed0df

Please sign in to comment.