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??
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??
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.
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?
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)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.