diff options
author | Saku Ytti <saku@ytti.fi> | 2014-07-11 18:42:22 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-07-11 18:42:22 +0300 |
commit | 20c3eac8aeb460c0ed8ecee6a73c2171e60f82eb (patch) | |
tree | e9b6abc0c734836f88bee53606ff246a8245a846 | |
parent | a7b2236d3a77fd268ffa9b76ee2c04a8e8f9e348 (diff) |
Bit friendlier error message on invalid config
Closes #20
[ytti@ytti.fi ~/tmp/oxidized]% oxidized
Error loading config: (<unknown>): mapping values are not s context at line 15 column 7
[ytti@ytti.fi ~/tmp/oxidized]%
-rwxr-xr-x | bin/oxidized | 1 | ||||
-rw-r--r-- | lib/oxidized/config.rb | 10 |
2 files changed, 9 insertions, 2 deletions
diff --git a/bin/oxidized b/bin/oxidized index f2fb9ff..e5d9bec 100755 --- a/bin/oxidized +++ b/bin/oxidized @@ -1,5 +1,6 @@ #!/usr/bin/env ruby + # FIX ME, killing oxidized needs -9 trap("INT") { exit } # sinatra will otherwise steal this from us 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 |