-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add optional chaining to fix NoMethodError #263
base: master
Are you sure you want to change the base?
Conversation
Hi @fdocr, could you please share the code sample that raised the above error? |
Sure, this is one example that raises the error on the current # Initial setup
client = Contentful::Management::Client.new(ENV["CONTENTFUL_TOKEN"], dynamic_entries: { ENV["CONTENTFUL_SPACE"] => "staging" })
environment = client.environments(ENV["CONTENTFUL_SPACE"]).find("staging")
# Sample one content type (issue happens with different content types not only the first one)
content_type = environment.content_types.all.first
# User specific query
user_id = "XXXXXXX"
entries = environment.entries.all("content_type" => content_type.id, 'sys.createdBy.sys.id' => user_id)
# Failure
entries.properties[:items].each { |entry| puts "INSPECTED ENTRY: #{entry.inspect}" } With those few lines on a Rails console I see the following error:
|
looks like a linting issue @rubydog any thoughts on this? I'm not familiar enough with ruby to know |
|
That makes sense @rubydog. I didn't think that through since it fixed the properties_info = properties.nil? || properties.empty? ? '' : " @properties=#{properties.inspect}" Rubocop seems to be okay with this. Please let me know if you have any alternatives for me to use instead. Thanks! |
Hi,
For some reason during my use of the gem I ran into this issue when trying to print out some entries while debugging. I can't seem to find an easy way to add spec coverage here but this solves a
NoMethodError
when properties arenil
.Feel free to push specs for coverage or point me out how to do so if needed.
Thanks!