hanami / model

Ruby persistence framework with entities and repositories
http://hanamirb.org
MIT License
445 stars 152 forks source link

More helpful error for nonexistent DB #430

Open cllns opened 7 years ago

cllns commented 7 years ago
 % b e rake
/Users/sean/.gem/ruby/2.3.3/gems/hanami-model-1.0.1/lib/hanami/model/configuration.rb:144:in `rescue in load!': PG::ConnectionBad: FATAL:  database "bookshelf_test" does not exist (Hanami::Model::Error)
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-model-1.0.1/lib/hanami/model/configuration.rb:134:in `load!'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-model-1.0.1/lib/hanami/model.rb:79:in `load!'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components/components.rb:83:in `block (2 levels) in <module:Components>'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components/component.rb:44:in `call'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:85:in `block (2 levels) in resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:133:in `block in fetch_or_store'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:122:in `fetch'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:132:in `fetch_or_store'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:83:in `block in resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:82:in `each'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:82:in `resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components/component.rb:138:in `resolve_requirements'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components/component.rb:36:in `call'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:85:in `block (2 levels) in resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:133:in `block in fetch_or_store'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:122:in `fetch'
    from /Users/sean/.gem/ruby/2.3.3/gems/concurrent-ruby-1.0.5/lib/concurrent/map.rb:132:in `fetch_or_store'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:83:in `block in resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:82:in `each'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami/components.rb:82:in `resolve'
    from /Users/sean/.gem/ruby/2.3.3/gems/hanami-1.0.0/lib/hanami.rb:92:in `boot'
...

Instead of just:

 database "bookshelf_test" does not exist (Hanami::Model::Error)

Should we say something like:

 database "bookshelf_test" does not exist (Hanami::Model::Error)
 TIP: In order to create and migrate this database, run: `HANAMI_ENV=test bundle exec hanami db prepare`

(only show the HANAMI_ENV part if it's already equal to 'test')

Thoughts?? @hanami/core

jodosha commented 7 years ago

@cllns yup 👍

AlfonsoUceda commented 7 years ago

This happens too when you run the server and access localhost:2300, it only happens with postgresql and not with mysql and sqlite. So I think we need to rescue that exception in our error classes and create something like Hanami::Model::ConnectionError.

@cllns will you take care of this?