0

I am using ActiveRecord to create a connection to a database in a thor script. The adapter I am using in this case is mysql2. I want to add some rescue blocks to my code in order to offer some specific error messages to users.

When I turn off the mysql server on my localhost and tried to connect (using establish_connection) I get the following error (as expected)

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error)

Why am I not getting an ActiveRecord::ConnectionNotEstablished error instead of the Mysql2::Error? The reason I ask is that Mysql2 does not have specific error types(based on https://github.com/brianmario/mysql2/blob/master/lib/mysql2/error.rb) whereas active record does( http://api.rubyonrails.org/files/activerecord/lib/active_record/errors_rb.html)

Using ruby 1.9.3 and activerecord 3.2.8 with mysql2 0.3.11

Thanks!

Satyam
  • 645
  • 2
  • 7
  • 20

1 Answers1

0

It seems to be a problem in finding the mysql socket

This link may help you out with that,

Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on OSX

Community
  • 1
  • 1
maximus ツ
  • 7,949
  • 3
  • 25
  • 54
  • I'm sorry, you might have misunderstood the question. The error happens because I **intentionally** switched off the server. What I am asking is that why is the error not an **ActiveRecord Error** but a **Mysql2** error when I am using ActiveRecord to establish a connection. – Satyam Sep 07 '12 at 05:43