Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

find_by_xxx! bang method, have better error messages

#1567

It would be nice if the find_by_xxx! bang methods gave nicer error messages. Right now you get:


> Expense.find_by_amount(10)
=> nil
>> Expense.find_by_amount!(10)
ActiveRecord::RecordNotFound: ActiveRecord::RecordNotFound

It would be better if the error produced was:


ActiveRecord::RecordNotFound: no Expense found with amount => 10

Reported by Zach Dennis · December 12th, 2008 @ 09:49 PM

State: resolved
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Frederick Cheung
    Frederick Cheung
    • Tag changed from featurerequest, rails to activerecord, featurerequest, patch, rails

    This should do it. If you use find_by_xxx_and_yyy! then the exception's message will be along the lines of

    Couldn't find Asset with xxx = 123, yyy = 456

    December 14th, 2008 @ 01:52 PM

  2. Repository
    Repository
    • State changed from new to resolved

    (from [428e77bf0fcee4369cb8d94011141f791b8e2ba9]) Make exceptions raise from find_by_foo! have a more helpful message [#1567 find_by_xxx! bang method, have better error messages state:resolved] http://github.com/rails/rails/co...

    December 18th, 2008 @ 07:22 PM