Browse files

Don't crash exception translation w/ nil result attribute.

Exception.result is nil when attempting a query after PostgreSQL
disconnect, resulting in new exception:
NoMethodError: undefined method `error_field' for nil:NilClass
  • Loading branch information...
1 parent 517060a commit be913c3964069fa9ff7c8a615e06705e3a6ec435 Steve Jorgensen committed with jonleighton May 21, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1144,7 +1144,7 @@ def postgresql_version
def translate_exception(exception, message)
- case exception.result.error_field(PGresult::PG_DIAG_SQLSTATE)
+ case exception.result.try(:error_field, PGresult::PG_DIAG_SQLSTATE)
when UNIQUE_VIOLATION, exception)

0 comments on commit be913c3

Please sign in to comment.