# Why is Logging Silent about SQL Errors?

**URL:** <https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352>\
**Category:** Rails\
**Created:** [November 16, 2007, 1:38am UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352 "2007-11-16T01:38:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 16, 2007, 1:38am UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/1 "2007-11-16T01:38:43Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 16, 2007, 4:53am UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/2 "2007-11-16T04:53:56Z")

</div>

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 W. wrote:

> 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)
> 
> >

–  
Sincerely,

William P.

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 16, 2007, 6:16am UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/3 "2007-11-16T06:16:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 17, 2007, 7:11pm UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/4 "2007-11-17T19:11:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 17, 2007, 8:11am UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/5 "2007-11-17T08:11:18Z")

</div>

On Nov 15, 2007 4:38 PM, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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?

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?

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [November 17, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/why-is-logging-silent-about-sql-errors/120352/6 "2007-11-17T23:08:26Z")

</div>

On Nov 16, 2007, at 11:10 PM, Cynthia K. wrote:

> somewhere – why no messages?
> 
> 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?

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)
