From 20c3eac8aeb460c0ed8ecee6a73c2171e60f82eb Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Fri, 11 Jul 2014 18:42:22 +0300 Subject: Bit friendlier error message on invalid config Closes #20 [ytti@ytti.fi ~/tmp/oxidized]% oxidized Error loading config: (): mapping values are not s context at line 15 column 7 [ytti@ytti.fi ~/tmp/oxidized]% --- lib/oxidized/config.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index 9c2faff..02698a6 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -1,6 +1,7 @@ module Oxidized require 'asetus' class NoConfig < OxidizedError; end + class InvalidConfig < OxidizedError; end class Config Root = File.join ENV['HOME'], '.config', 'oxidized' Crash = File.join Root, 'crash' @@ -39,8 +40,13 @@ module Oxidized 'juniper' => 'junos', } - CFGS.load # load system+user configs, merge to Config.cfg - CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password + begin + CFGS.load # load system+user configs, merge to Config.cfg + rescue => error + raise InvalidConfig, "Error loading config: #{error.message}" + ensure + CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password + end Log.level = Logger::INFO unless CFG.debug raise NoConfig, 'edit ~/.config/oxidized/config' if CFGS.create -- cgit v1.2.1