diff options
author | elijah <elijah@riseup.net> | 2012-11-13 22:49:32 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2012-11-13 22:49:32 -0800 |
commit | 10bd0ba9d66a32cb8e0f7fb322843005b23181b7 (patch) | |
tree | 5768b4fc787b189b5df9035596d7de945342852f /lib/leap_cli/config | |
parent | 622236c3ad6abc4aef200cc2d4fc2a09effd8647 (diff) |
cleaned up logging, and much improved error message when file is not found
Diffstat (limited to 'lib/leap_cli/config')
-rw-r--r-- | lib/leap_cli/config/manager.rb | 10 | ||||
-rw-r--r-- | lib/leap_cli/config/object.rb | 27 |
2 files changed, 22 insertions, 15 deletions
diff --git a/lib/leap_cli/config/manager.rb b/lib/leap_cli/config/manager.rb index 00b4ec5..7406f1c 100644 --- a/lib/leap_cli/config/manager.rb +++ b/lib/leap_cli/config/manager.rb @@ -140,7 +140,7 @@ module LeapCli return Config::Object.new(self) end - progress2("loading %s" % filename) + log :loading, filename, 2 # # read file, strip out comments @@ -158,8 +158,8 @@ module LeapCli begin hash = JSON.parse(buffer.string, :object_class => Hash, :array_class => Array) || {} rescue SyntaxError => exc - log0 'Error in file "%s":' % filename - log0 exc.to_s + log 0, :error, 'in file "%s":' % filename + log 0, exc.to_s, :indent => 1 return nil end object = Config::Object.new(self) @@ -198,7 +198,7 @@ module LeapCli node['services'].to_a.sort.each do |node_service| service = @services[node_service] if service.nil? - log0('Error in node "%s": the service "%s" does not exist.' % [node['name'], node_service]) + log 0, :error, 'in node "%s": the service "%s" does not exist.' % [node['name'], node_service] else new_node.deep_merge!(service) service.node_list.add(name, new_node) @@ -211,7 +211,7 @@ module LeapCli node['tags'].to_a.sort.each do |node_tag| tag = @tags[node_tag] if tag.nil? - log0('Error in node "%s": the tag "%s" does not exist.' % [node['name'], node_tag]) + log 0, :error, 'in node "%s": the tag "%s" does not exist.' % [node['name'], node_tag] else new_node.deep_merge!(tag) tag.node_list.add(name, new_node) diff --git a/lib/leap_cli/config/object.rb b/lib/leap_cli/config/object.rb index 731f3ff..bf0452a 100644 --- a/lib/leap_cli/config/object.rb +++ b/lib/leap_cli/config/object.rb @@ -170,11 +170,16 @@ module LeapCli global.nodes end + class FileMissing < Exception; end + # # inserts the contents of a file # def file(filename) - filepath = Path.find_file(@node.name, filename) + if filename.is_a? Symbol + filename = [filename, @node.name] + end + filepath = Path.find_file(filename) if filepath if filepath =~ /\.erb$/ ERB.new(File.read(filepath), nil, '%<>').result(binding) @@ -182,7 +187,7 @@ module LeapCli File.read(filepath) end else - log0('no such file, "%s"' % filename) + raise FileMissing.new(Path.named_path(filename)) "" end end @@ -213,16 +218,18 @@ module LeapCli value = @node.instance_eval($1) #, @node.send(:binding)) self[key] = value rescue SystemStackError => exc - puts "STACK OVERFLOW, BAILING OUT" - puts "There must be an eval loop of death (variables with circular dependencies). This is the offending string:" - puts - puts " #{$1}" - puts + log :error, "while evaluating node '#{@node.name}'" + log "offending string: #{$1}", :indent => 1 + log "STACK OVERFLOW, BAILING OUT. There must be an eval loop of death (variables with circular dependencies)." raise SystemExit.new() + rescue FileMissing => exc + log :error, "while evaluating node '#{@node.name}'" + log "offending string: #{$1}", :indent => 1 + log "error message: no file '#{exc}'", :indent => 1 rescue StandardError => exc - puts "Eval error in '#{@node.name}'" - puts " string: #{$1}" - puts " error: #{exc.name}" + log :error, "while evaluating node '#{@node.name}'" + log "offending string: #{$1}", :indent => 1 + log "error message: #{exc}", :indent => 1 end end value |