Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't blindly call blame_file! on exceptions in ActiveSupport::Depend…

…encies::Loadable

It is possible under some environments to receive an Exception that is
not extended with Blamable (e.g. JRuby).
ActiveSupport::Dependencies::Loadable#load_dependency blindly call
blame_file! on the exception which throws it's own NoMethodError
exception and hides the original Exception.

This commit fixes #9521
  • Loading branch information...
commit 14fda489bde982fd182b0d6f9d1c5862435ecdf2 1 parent b8e2978
@akreiling akreiling authored steveklabnik committed
View
5 activesupport/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Fix `ActiveSupport::Dependencies::Loadable#load_dependency` calling
+ `#blame_file!` on Exceptions that do not have the Blamable mixin
+
+ *Andrew Kreiling*
+
* Override `Time.at` to support the passing of Time-like values when called with a single argument.
*Andrew White*
View
2  activesupport/lib/active_support/dependencies.rb
@@ -213,7 +213,7 @@ def load_dependency(file)
yield
end
rescue Exception => exception # errors from loading file
- exception.blame_file! file
+ exception.blame_file! file if exception.respond_to? :blame_file!
raise
end
View
5 activesupport/test/dependencies/raises_exception_without_blame_file.rb
@@ -0,0 +1,5 @@
+exception = Exception.new('I am not blamable!')
+class << exception
+ undef_method(:blame_file!)
+end
+raise exception
View
8 activesupport/test/dependencies_test.rb
@@ -76,6 +76,14 @@ def test_dependency_which_raises_exception_isnt_added_to_loaded_set
end
end
+ def test_dependency_which_raises_doesnt_blindly_call_blame_file!
+ with_loading do
+ filename = 'dependencies/raises_exception_without_blame_file'
+
+ assert_raises(Exception) { require_dependency filename }
+ end
+ end
+
def test_warnings_should_be_enabled_on_first_load
with_loading 'dependencies' do
old_warnings, ActiveSupport::Dependencies.warnings_on_first_load = ActiveSupport::Dependencies.warnings_on_first_load, true
Please sign in to comment.
Something went wrong with that request. Please try again.