Permalink
Browse files

Exceptions from database adapters should not lose their backtrace.

  • Loading branch information...
1 parent 9c2ff32 commit a748c600dddcc894adb0d8e427d7f2c7bc13528b @tenderlove tenderlove committed Sep 9, 2011
@@ -1,5 +1,7 @@
* Rails 3.0.11 (unreleased)
+* Exceptions from database adapters should not lose their backtrace.
+
* Backport "ActiveRecord::Persistence#touch should not use default_scope" (GH #1519)
* Psych errors with poor yaml formatting are proxied. Fixes GH #2645 and
@@ -204,7 +204,9 @@ def log(sql, name)
rescue Exception => e
message = "#{e.class.name}: #{e.message}: #{sql}"
@logger.debug message if @logger
- raise translate_exception(e, message)
+ ex = translate_exception(e, message)
+ ex.set_backtrace e.backtrace
+ raise ex
end
def translate_exception(e, message)
@@ -13,6 +13,13 @@ def test_tables
assert tables.include?("topics")
end
+ def test_exception
+ ex = assert_raises(ActiveRecord::StatementInvalid) do
+ @connection.execute 'this is bad sql'
+ end
+ assert ex.backtrace.grep(/rescue in/).empty?, 'bactrace should not include rescue'
+ end
+
def test_table_exists?
assert @connection.table_exists?("accounts")
assert !@connection.table_exists?("nonexistingtable")

0 comments on commit a748c60

Please sign in to comment.