summaryrefslogtreecommitdiff
path: root/lib/leap_cli/config
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2015-07-08 17:00:28 -0700
committerelijah <elijah@riseup.net>2015-07-08 17:00:28 -0700
commitf528ccc241b88d49eb33bfc9b260a569d7651b48 (patch)
tree1e04fb72b5217c1fe3ecf88cf8f92e061c90dca2 /lib/leap_cli/config
parent4c5284b40321393dfeb02a20e4cf3942df008b07 (diff)
die more gracefully if facts.json is corrupted.
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r--lib/leap_cli/config/manager.rb10
1 files changed, 9 insertions, 1 deletions
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
#