Permalink
Browse files

Wrong exception is occured when raising no translatable exception

  • Loading branch information...
1 parent 8f6b70f commit e2a4b7a506e36839771284942829cbbe8d40b377 @kennyj kennyj committed Feb 28, 2013
@@ -1,5 +1,10 @@
## Rails 4.0.0 (unreleased) ##
+* Fix a problem wrong exception is occured
+ when raising no translatable exception in PostgreSQL.
+
+ *kennyj*
+
* Support PostgreSQL specific column types when using `change_table`.
Fixes #9480.
@@ -675,6 +675,8 @@ def postgresql_version
UNIQUE_VIOLATION = "23505"
def translate_exception(exception, message)
+ return exception unless exception.respond_to?(:result)
+
case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION
RecordNotUnique.new(message, exception)
@@ -250,6 +250,12 @@ def test_distinct_with_nulls
assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"])
end
+ def test_raise_error_when_cannot_translate_exception
+ assert_raise TypeError do
+ @connection.send(:log, nil) { @connection.execute(nil) }
+ end
+ end
+
private
def insert(ctx, data)
binds = data.map { |name, value|

0 comments on commit e2a4b7a

Please sign in to comment.