Ticket #7452: add_error_option.2.diff
| File add_error_option.2.diff, 3.5 kB (added by rogerdpack, 11 months ago) |
|---|
-
dependencies.rb
old new 2 2 require 'active_support/core_ext/module/attribute_accessors' 3 3 require 'active_support/core_ext/load_error' 4 4 require 'active_support/core_ext/kernel' 5 6 5 module Dependencies #:nodoc: 7 6 extend self 8 7 … … 10 9 mattr_accessor :warnings_on_first_load 11 10 self.warnings_on_first_load = false 12 11 12 # Should we warn on all errors? 13 mattr_accessor :warn_on_all_errors 14 self.warn_on_all_errors = false 15 13 16 # All files ever loaded. 14 17 mattr_accessor :history 15 18 self.history = Set.new … … 58 61 def depend_on(file_name, swallow_load_errors = false) 59 62 path = search_for_file(file_name) 60 63 require_or_load(path || file_name) 61 rescue LoadError 64 rescue LoadError => detail 65 log_error "depend on #{file_name} returned LoadError: #{detail}" 62 66 raise unless swallow_load_errors 63 67 end 64 68 … … 95 99 else 96 100 enable_warnings { result = load_file(*load_args) } 97 101 end 98 rescue Exception 102 rescue Exception => detail 103 log_error "error during a load #{file_name} #{detail}" 99 104 loaded.delete expanded 100 105 raise 101 106 end … … 246 251 file_path = search_for_file(path_suffix) 247 252 if file_path && ! loaded.include?(File.expand_path(file_path)) # We found a matching file to load 248 253 require_or_load file_path 249 raise LoadError, "Expected #{file_path} to define #{qualified_name} " unless from_mod.const_defined?(const_name)254 raise LoadError, "Expected #{file_path} to define #{qualified_name}--check path, and logs, modify warnings levels in #{__FILE__}." unless from_mod.const_defined?(const_name) 250 255 return from_mod.const_get(const_name) 251 256 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix) 252 257 return mod … … 341 346 begin 342 347 yield # Now yield to the code that is to define new constants. 343 348 aborting = false 349 rescue Exception => detail 350 log_error "error thrown in #{descs.inspect} #{detail}" # log it here, too 351 raise 344 352 ensure 345 353 # Find the new constants. 346 354 new_constants = watch_frames.collect do |mod_name, prior_constants| … … 369 377 new_constants.clear 370 378 end 371 379 end 372 373 380 return new_constants 374 381 ensure 375 382 # Remove the stack frames that we added. 376 if defined?(watch_frames) && ! watch_frames.empty?383 if defined?(watch_frames) && watch_frames && ! watch_frames.empty? 377 384 frame_ids = watch_frames.collect(&:object_id) 378 385 constant_watch_stack.delete_if do |watch_frame| 379 386 frame_ids.include? watch_frame.object_id … … 429 436 log "called #{selector}(#{arg_str})" 430 437 end 431 438 432 def log(msg) 433 if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER && log_activity 434 RAILS_DEFAULT_LOGGER.debug "Dependencies: #{msg}" 439 def log_error(msg) 440 if warn_on_all_errors 441 log(msg, true) 442 else 443 log(msg, false) 444 end 445 end 446 447 def log(msg, is_error = false) 448 new_message = "Dependencies: #{msg}" 449 if defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER 450 if is_error 451 RAILS_DEFAULT_LOGGER.error new_message # log error activity high, as requested. 452 elsif log_activity 453 RAILS_DEFAULT_LOGGER.debug new_message # log normal activity 454 end 455 else 456 if log_activity or is_error 457 print new_message + "\n" # print it to stdout, at least, as there's no logger around 458 end 435 459 end 436 460 end 437 461