In my Rails 3.0.11 app, we have very simple code in a controller:
def index
@record = Record.valid # scope around 80,000 records
asdfasdfsa # consider this is a typo to raise NameError Exception
end
The interesting thing is that when it came to the typo, the app seems to query/execute the @record instance variable first before raising an exception. The query costs almost 1 min to get records. So in browser, the page hanges for a long while before coming into an exception template.
If I replace @record with a local variable “record”, the querying doesn’t happen at all. Anyone knows what it is going on?
See my blog post Ruby’s Inspect Considered Harmful for details about this very issue. In short, though:
inspectwhen formatting its error messageinspectcallsinspecton all instance variables recursivelyinspectif it is longer than 65 charactersIn short, I consider the behaviour of NameError to be a heinous bug within the Ruby interpreter. I can think of no sane reason for this implementation.