Skip to content

Commit

Permalink
Bit friendlier error message on invalid config
Browse files Browse the repository at this point in the history
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]%
  • Loading branch information
ytti committed Jul 11, 2014
1 parent a7b2236 commit 20c3eac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions bin/oxidized
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby


# FIX ME, killing oxidized needs -9
trap("INT") { exit } # sinatra will otherwise steal this from us

Expand Down
10 changes: 8 additions & 2 deletions lib/oxidized/config.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -39,8 +40,13 @@ class << self
'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
Expand Down

0 comments on commit 20c3eac

Please sign in to comment.