#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Thumbs down Non empty string complained to be 'nil' in equality check


    I have the below code
    response = Net::HTTP.start(url.host, url.port) do
    |http|
    http.request(request)
    end
    exp_code = 450
    if(response.code.to_i != exp_code)
    raise StandardError, "Expected #{exp_code} Received
    #{response.code.to_i}"
    end
    exp_msg = 'Blocked By Parental Controls'
    puts 'Received status msg: #{response.message}'
    if(response.message != exp_msg)
    raise StandardError, "Expected #{exp_msg} Received
    #{response.message}"
    end

    The received response is
    HTTP/1.1 450 Blocked By Parental Controls^M
    Date: Mon, 12 Apr 2010 10:28:15 GMT^M
    P3P: policyref="(blah url)", CP="CAO DSP COR CUR
    ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
    PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"^M
    cache-control: public,must-revalidate^M
    Content-Length: 0^M
    Connection: close^M
    Content-Type: ^M
    ^M

    The "puts" statement is printing
    Received status msg: Blocked By Parental Controls

    But the next statement for inequality check fails with
    can't convert nil to string

    However for a different case, where the response is
    HTTP/1.1 200 OK^M
    Date: Mon, 12 Apr 2010 10:28:29 GMT^M
    P3P: policyref="(blah url)", CP="CAO DSP COR CUR
    ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
    PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"^M
    cache-control: public,must-revalidate^M
    Content-Length: 0^M
    Connection: close^M
    Content-Type: ^M
    ^M

    and I have the ruby code as:
    exp_msg = 'OK'
    puts 'Received status msg: #{response.message}'
    if(response.message != exp_msg)
    raise StandardError, "Expected #{exp_msg} Received
    #{response.message}"
    end

    Here there is no nil problem.
    I have been breaking my head and don't have the slightest clue what is
    happening. Can somebody please shed some light?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Katy, Texas
    Posts
    495
    Rep Power
    199
    As you say, this line is giving you the error:
    Code:
    if(response.message != exp_msg)
    That error cannot happen on that line, unless response is nil, and based on how far you have gotten, that can't happen either.

    I would suggest you add some more diagnostics to your code.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0
    I know it can't happen, I have no clue. Just before the if statement I'm printing response.message it is printing the value.
    Never encountered something so weird.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0
    goddammit, i was fooled because the if statement was teh last statement in the code. The error didnt happen there at all. This code is a Ruby testframework code so it supposed to return a true/false and I was not returning, and that has caused the cruelly meaningless error message.
    sorry for wasting everyone's time.

IMN logo majestic logo threadwatch logo seochat tools logo