TypeError: can't convert nil into String #183

Open
matthewepler opened this Issue Feb 12, 2012 · 8 comments

7 participants

@matthewepler

I have already deployed this app to herouku and it was working fine. I went in to make some aesthetic changes, and started to get this error. I'm really new to Ruby, bash, and heroku - so I assume I did something I shouldn't have. Any guidance will be much appreciated.

In the code below, "Can" is a class created in DataMapper. I then migrated and updated to sqlite and pushed to heroku.

>> require 'app.rb'
=> true
>> Can.count
TypeError: can't convert nil into String
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/connection.rb:79:in `initialize'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/connection.rb:79:in `send'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/connection.rb:79:in `__new'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/pooling.rb:177:in `new'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/pooling.rb:172:in `synchronize'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/pooling.rb:172:in `new'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/pooling.rb:119:in `new'
    from /Library/Ruby/Gems/1.8/gems/data_objects-0.10.7/lib/data_objects/connection.rb:68:in `new'
    from /Library/Ruby/Gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:251:in `open_connection'
    from /Library/Ruby/Gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
    from /Library/Ruby/Gems/1.8/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:141:in `read'
    from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/repository.rb:162:in `read'
    from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/collection.rb:1117:in `lazy_load'
    from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/support/lazy_array.rb:409:in `each'
    from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/collection.rb:504:in `each'
    from /Library/Ruby/Gems/1.8/gems/dm-core-1.2.0/lib/dm-core/model.rb:317:in `each'
    from (irb):2:in `count'
    from (irb):2>> 
@runemadsen

I'm having the exact same issue, running Ruby 1.9.3. Even with a very slim model with 1 property it fails.

@hovatterz

Also having this issue.

@dkubb
DataMapper member

It looks like this isn't happening in anything related to DataMapper's dm-core project, but rather in the database driver called DataObjects.

Can someone who's seeing this problem open up an issue in the DataObjects project at https://github.com/datamapper/do with information to reproduce it, and then add a link to here, and from here to it? Once that's done this issue can be closed and worked out with the DO maintainers. Thanks!

@hovatterz

Figured this one out. The documentation instructs you to use a path like DataMapper.setup(:default, 'sqlite:///path/to/project.db') when really you need a path like DataMapper.setup(:default, "sqlite:test.db") (without the double slashes that the other URIs require).

Not sure if that's correct behavior or not, but it fixes things.

@dkubb
DataMapper member

@hovatterz well, the one without the slashes is a relative path. This is fine if you want to have something be relative to your current working directory. Sometimes it's not always convenient though.

What I'm guessing is that there's something in the internals of DO that assumes something is always going to be a string, but it turns out to be a nil value and ruby can't coerce it.

@godfat

I am not sure how to reproduce this, but just throwing some ideas, and hope that would help.
I have a datamapper plugin called dm-is-reflective which has a small issue with sqlite:
https://github.com/godfat/dm-is-reflective/blob/b77b1b6357eaad98c8cd96b413b75d143f79e81f/lib/dm-is-reflective/is/adapters/data_objects_adapter.rb#L145-147

# TODO: can we fix this adapter name in dm-sqlite-adapter?
adapter = options[:adapter].sub(/\Asqlite3\Z/, 'sqlite')

Previously, I was using options[:scheme], I don't remember why I changed to options[:adapter]. Anyway, this might somehow to be related, where scheme and adapter got mixed somewhere maybe. It would be good if those two could be merged, otherwise it's confusing.

@rupe

@hovatterz your solution worked for me as well, but I really don't understand why it did.

@darylshy

Hi, I know this post is 2 years old, but I just wanted to say thank you to @hovatterz for his solution. I've been searching for the last 3 hours, yours is the only thing that work'd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment