From 598e4760dbc1d43bffba5201a7910b2048ec744c Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Tue, 29 Jan 2013 12:34:00 -0800 Subject: [PATCH] better error messaging. --- cornfig/cornfig.py | 7 +++++-- tests/cornfig_tests.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cornfig/cornfig.py b/cornfig/cornfig.py index b4f3897..8f5a210 100755 --- a/cornfig/cornfig.py +++ b/cornfig/cornfig.py @@ -55,7 +55,10 @@ def render_executable(path, config): raise CornfigException("config script failed: %s\n\nwith output:\n\n%s" % (path, e.output)) def read_config(path): - return json.loads(open(path).read()) + try: + return json.loads(open(path).read()) + except: + raise CornfigException("invalid metadata file: %s" % path) # flatten a nested hash into a one-level hash # {x: {a: b} } => {x.a: b} @@ -103,7 +106,7 @@ def main(): install_cornfig(options.metadata_path, options.template_root, options.out_root) except CornfigException as e: - logging.error(e.message()) + logging.error(e) sys.exit(1) if __name__ == '__main__': diff --git a/tests/cornfig_tests.py b/tests/cornfig_tests.py index 69820fc..500b484 100644 --- a/tests/cornfig_tests.py +++ b/tests/cornfig_tests.py @@ -83,7 +83,7 @@ def test_read_config(): t.flush() assert_equals( read_config(t.name), d ) -@raises(ValueError) +@raises(CornfigException) def test_read_config_bad_json(): with tempfile.NamedTemporaryFile() as t: t.write("{{{{")