Skip to content
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

nil #65

Open
IvoWalach opened this issue Aug 11, 2022 · 3 comments
Open

nil #65

IvoWalach opened this issue Aug 11, 2022 · 3 comments

Comments

@IvoWalach
Copy link

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

@buntine
Copy link
Owner

buntine commented Aug 15, 2022

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.

@IvoWalach
Copy link
Author

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
Copy link
Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants