Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate .find_by raising an error #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

p8
Copy link
Contributor

@p8 p8 commented Jul 30, 2024

RemoteResource.find_by raises a RemoteResource::HTTPNotFound error if the resource can't be found. This is unexpected as ActiveRecord::Base.find_by doesn't raise when the record can't be found.
ActiveRecord::Base.find_by! does raise an error.

Current implementation:

ActiveRecord::Base RemoteResource
find_by return nil raises
find_by! raises not implemented

Having a RemoteResource.find_by method that doesn't raise can be useful, as we currently rescue the RemoteResource::HTTPNotFound error instead in a lot of places. To make RemoteResource behave more like ActiveRecord and have separate finder methods that raise or return nil we can add a .find_by! method that raises and let .find_by return nil instead:

ActiveRecord::Base RemoteResource
find_by return nil return nil
find_by! raises raises

As .find_by is used a lot, we deprecate it first in this PR. In version 2.0 we can make .find_by return nil instead.
This PR:

ActiveRecord::Base RemoteResource
find_by return nil raises and shows a deprecation warning
find_by! raises raises

`.find_by` raises a `RemoteResource::HTTPNotFound` error if the resource
can't be found. This is unexpected as `ActiveRecord::Base.find_by`
doesn't raise when the record can't be found.
`ActiveRecord::Base.find_by!` does raise an error.

To make RemoteResource behave more like ActiveRecord and have separate
finder methods that raise or return `nil` we can add a `.find_by!`
method that raises and let `.find_by` return `nil` instead.

As `.find_by` is used a lot, we deprecate it first.
In version 2.0 we can make `.find_by` return `nil` instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant