Why is Logging Silent about SQL Errors?

I’m experimenting to understand how Rails deals with various errors.

When there’s a Ruby or Rails syntax error, we get the stack trace.

However, when there’s an SQL error, the entire application appears to be silent about it.

In dev mode, and made sure logging was explicitly set to debug.

If I do somthing like change a field name in a table to ensure a failure, the development.log says nothing about it. I know the query failed, and the partial which would have displayed data from the query doesn’t get drawn, so Rails has to be detecting failures somewhere – why no messages??

– gw (www.railsdev.ws)

Hmm, are you running this inside of a begin block or rescuing it at
some point? When I encounter sql errors, I get a full stack track along
with the error returned from Mysql. Is this on create / update / insert
or on selecting records?

-Bill

Greg Willits wrote:

Having a begin/rescue structure or not doesn’t change the behavior.

I have coordinated the error to happen with a find and with an update_attributes (by changing a field name just before trigging a specific action).

If it is normal to get some messaging, then it has to be some detail in my environment.

I’ll dig deeper.

– gw

Are you writing explicit queries or using a find_by_xxx where xxx is a field that does not exist in the database? From your description, I suspect the SQL isn’t erroring - it just isn’t returning the results you expect. If you copy the SQL out of the development log into mysql (or pgsql or whatever your database querying tool is), do you get an error? or do you just get 0 rows returned?

He was purposefully causing a sql error by changing the schema. He would remove a column then query on it. It has to be something with his environment or he is rescuing it somewhere.

-Bill

I’m using find(:all

There’s a good chance the apparaent silence is caused by something else. By changing the field name, that changes a bunch of controller/view code as well. I’m now not convinced that the code even got as far as executing the query.

I see a lot of this behavior from Rails where if something is wrong deep in a model but the impact of that isn’t realized until a partial is rendered, that the only indicator of trouble I get is that the partial does not render. NO error messages of any kind, just a specific partial doesn’t render (the rest of the page does).

So, I’ve abandoned blaming the query at this point, and will eventually approach that testing another way.

I’ll dig into it later. Right now I have some brain momentum going in other directions I want to let run its course.

Thanks. Bill’s acknowledgement that an error dump should be generated is enough for me to know that something else going on. I’ll figure it out later.

– gw (www.railsdev.ws)