lib/autoproj/base.rb in autoproj-1.6.2 vs lib/autoproj/base.rb in autoproj-1.7.0.b1

- old
+ new

@@ -1,6 +1,28 @@ module Autoproj - class ConfigError < RuntimeError; end + class ConfigError < RuntimeError + attr_accessor :file + def initialize(file = nil) + super + @file = file + end + end class InternalError < RuntimeError; end + + # Yields, and if the given block raises a ConfigError with no file assigned, + # add that file to both the object and the exception message + def self.in_file(file, exception_t = ConfigError) + yield + + rescue exception_t => e + if exception_t != ConfigError + raise ConfigError.new(file), "in #{file}: #{e.message}", e.backtrace + elsif !e.file + e.file = file + raise e, "in #{file}: #{e.message}", e.backtrace + else + raise e + end + end end