jnunemaker / jnunemaker/httparty

HTTParty::Response fakes nil

Open
#285 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.9k
Forks
973
Avg merge
1h 59m
Merged PRs (30d)
1

Description

HTTParty::Response sometimes looks nil but isn't. This makes for some interesting consequences and strange code in order to deal with them:

[1] pry(#Salesforce::Rest)> response
=> nil
[2] pry(#Salesforce::Rest)> response.code
=> 413
[4] pry(#Salesforce::Rest)> response.class
=> HTTParty::Response
[11] pry(#Salesforce::Rest)> response == nil
=> false
[12] pry(#Salesforce::Rest)> response.nil?
=> true
[13] pry(#Salesforce::Rest)> !!response
=> true

So in my code I have:
if !((200..299).include?(response.code))
if response.nil?
raise "SF ERROR #{response.code}" # fake nil, not a bug
else
raise "SF ERROR '#{response.message}': #{response.first['message']}"
end
end

As I see it there are two problems:

  1. Response#inspect returns 'nil'
  2. Response#nil? somehow returns true

I don't know why (2) happens, something to do with Ruby's internal implementation of .nil?, which is defined in Object.

Perhaps you can suggest an improvement for my error detecting code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with HTTParty::Response, then inspect its inspect and nil? behavior. The issue does not name files or tests; done should mean establishing the intended nil semantics and adding coverage for the observed response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.