From 9c715f8b2abdba91ec7a91fba04eca8e29c42b74 Mon Sep 17 00:00:00 2001 From: Samuel Hoffstaetter Date: Fri, 21 Aug 2020 16:32:48 -0700 Subject: [PATCH] Raise an error when template key cannot be found --- chevron/renderer.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chevron/renderer.py b/chevron/renderer.py index 01476fd..e6bb2b7 100644 --- a/chevron/renderer.py +++ b/chevron/renderer.py @@ -32,6 +32,9 @@ def unicode(x, y): # Helper functions # +class TemplateError(BaseException): + pass + def _html_escape(string): """HTML escape all of these " & < >""" @@ -96,7 +99,7 @@ def _get_key(key, scopes, warn=False): # We couldn't find the key in any of the scopes if warn: - sys.stderr.write("Could not find key '%s'%s" % (key, linesep)) + raise TemplateError("Missing a value for key '%s'" % (key, )) return ''