discogs icon indicating copy to clipboard operation
discogs copied to clipboard

nil

Open IvoWalach opened this issue 3 years ago • 3 comments

Hey, the methods that return hashies kind of dont always work... i tried to get some information from them using the [] method but it sometimes outputs an error "undefined method `[]' for nil:NilClass", so it treats it as nil? im very confused an dont know how to fix that. Can you help me please? Thank you

IvoWalach avatar Aug 11 '22 19:08 IvoWalach

Hey, do you have some example code that can replicate the issue?

I would imagine that some fields are optional in the Discogs API, so when they are not present the value will be a nil and not an instance of a Hashie.

buntine avatar Aug 15 '22 06:08 buntine

Yeah. Im trying to obtain an artist using an album - release = wrapper.get_release("123") Now in order to obtain the artist, i did release.artists[0].name (the artist returns a hashie, so i used the [] method to get the first entry and then .name to get the name - everything should be according to the documentation of the hashie class.) But this simply sometimes works, and sometimes doesnt. As i said - it sometimes returns an error as though it was not a hashie class, but a nil class.

Maybe it is something similar to the other issue "Map missing arrays from nil to [] ?"

Thank you very much for your help

IvoWalach avatar Aug 19 '22 12:08 IvoWalach

I noticed that the console says

[DEPRECATED]: The key 'type_' has been replaced with 'type'. When accessing, please use the latter. This message will be removed in the next major release. You are setting a key that conflicts with a built-in method Hashie::Mash#type_ defined in Hashie::Mash. This can cause unexpected behavior when accessing the key as a property. You can still access the key via the #[] method.

I guess thats where the problem is, but I dont really understand what it says...

IvoWalach avatar Aug 22 '22 12:08 IvoWalach