Skip to content

Commit

Permalink
Use a more specific rescue to avoid hiding unexpected errors
Browse files Browse the repository at this point in the history
To test, we can do the following:

```
$ bin/rake db:drop
$ bin/rails c # should not blow up

$ bin/rake db:create
$ bin/rails c
> Settings.log.level # => "info"

$ bin/rake db:migrate
$ bin/rails c
> Settings.log.level # => "info"

$ bin/rake db:seed
$ bin/rails c
> Settings.log.level # => "info"
> Vmdb::Settings.save!(MiqServer.my_server, :log => {:level => "debug"})
> Settings.reload!
> Settings.log.level # => "debug"

$ bin/rails c
> Settings.log.level # => "debug"
```
  • Loading branch information
Fryguy committed Feb 10, 2021
1 parent 705445c commit 02c67e3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/vmdb/settings/database_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def resource_queryable?
end

def database_connectivity?
conn = ActiveRecord::Base.connection rescue nil
conn && ActiveRecord::Base.connected?
ActiveRecord::Base.connection && ActiveRecord::Base.connected?
rescue ActiveRecord::NoDatabaseError
false
end
end
end
Expand Down

0 comments on commit 02c67e3

Please sign in to comment.