-
Notifications
You must be signed in to change notification settings - Fork 566
Avoid exception when db-connection is lost #717
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,8 +152,7 @@ def disable_referential_integrity | |
|
||
def active? | ||
return false unless @connection | ||
raw_connection_do 'SELECT 1' | ||
true | ||
raw_connection_do('SELECT 1') == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO the previous one before the change is more robust. No matter how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem with the previous version is that if raw_connection do does not return 1, but for example There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally I'd like to point out that I did not get rid of the rescue block, so the previous behaviour of returning false if an connection_errors is raised is still the same. |
||
rescue *connection_errors | ||
false | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is essentially the same thing, but
might be more concise.
I did not review the functionality of the change, though.
I am just telling you an idiomatic ruby trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not the same.
will return result if it is any falsy value.
When you look at the tiny_tds lib, you will see that it should either returns false or a result object which then can be called do on it.
In any other case - for example
nil
- I don't want it to return nil, but cause an exception, so it's easier to figure out what is going wrong.