From f528ccc241b88d49eb33bfc9b260a569d7651b48 Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 8 Jul 2015 17:00:28 -0700 Subject: die more gracefully if facts.json is corrupted. --- lib/leap_cli/config/manager.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 33b7f05..2b4d0f5 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -43,7 +43,15 @@ module LeapCli # returns the Hash of the contents of facts.json # def facts - @facts ||= JSON.parse(Util.read_file(:facts) || "{}") + @facts ||= begin + content = Util.read_file(:facts) + if !content || content.empty? + content = "{}" + end + JSON.parse(content) + rescue SyntaxError, JSON::ParserError => exc + Util::bail! "Could not parse facts.json -- #{exc}" + end end # -- cgit v1.2.3