WinRb / Viewpoint

A Ruby client access library for Microsoft Exchange Web Services (EWS)
Apache License 2.0
248 stars 171 forks source link

Exception in code #242

Open SternAndrew opened 8 years ago

SternAndrew commented 8 years ago

I would fix this but not yet sure where the check should be to prevent this issue. Here is the stack trace of the exception:


/home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/ews_response.rb:31:in `envelope': undefined method `[]' for nil:NilClass (NoMethodError)
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/ews_response.rb:39:in `body'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/ews_response.rb:43:in `response'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/ews_response.rb:64:in `simplify!'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/ews_response.rb:27:in `initialize'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/parsers/ews_parser.rb:32:in `new'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/parsers/ews_parser.rb:32:in `parse'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/exchange_web_service.rb:221:in `parse_soap_response'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/connection.rb:74:in `dispatch'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/exchange_web_service.rb:212:in `do_soap_request'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/soap/exchange_data_services.rb:87:in `get_item'
        from /home/astern/.gem/ruby/gems/viewpoint-1.0.0/lib/ews/item_accessors.rb:33:in `get_item'
        from /cygdrive/c/Users/astern/Desktop/outlook.rb:60:in `block in <main>'
        from /cygdrive/c/Users/astern/Desktop/outlook.rb:59:in `each'
        from /cygdrive/c/Users/astern/Desktop/outlook.rb:59:in `<main>'

Here is the code path from the initialize. Its' clear that '@resp[:envelope][:elems]' is the [] on nil it is complaining about.

    def initialize(sax_hash)
      @resp = sax_hash
>>      simplify!
    end

    def simplify!
>>      response_type = response.keys.first
      response[response_type][:elems][0][:response_messages][:elems].each do |rm|
        key = rm.keys.first
        rm[key][:elems] = rm[key][:elems].inject(&:merge)
      end
    end

    def response
>>      body[0]
    end

    def body
>>      envelope[1][:body][:elems]
    end

    def envelope
>>      @resp[:envelope][:elems]
    end
jeffcarbs commented 8 years ago

I'm seeing a similar issue. Here's the stack trace:

NoMethodError: undefined method `each' for nil:NilClass
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/ews_response.rb:65:in `simplify!'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/ews_response.rb:27:in `initialize'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/parsers/ews_parser.rb:32:in `new'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/parsers/ews_parser.rb:32:in `parse'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/exchange_web_service.rb:221:in `parse_soap_response'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/connection.rb:78:in `dispatch'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/exchange_web_service.rb:212:in `do_soap_request'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/soap/exchange_data_services.rb:52:in `find_item'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/types/generic_folder.rb:79:in `items'
    from /app/vendor/bundle/ruby/2.3.0/bundler/gems/Viewpoint-5475b290d558/lib/ews/types/generic_folder.rb:107:in `items_between'

The server we're looking at is Exchange version 2010.

Here's the pretty-printed response from find_items before the call to items_parser (which is the line that crashes):

#<Viewpoint::EWS::SOAP::EwsResponse:0x007f94ece8da40
 @resp=
  {:envelope=>
    {:elems=>
      [{:header=>
         {:elems=>
           [{:server_version_info=>
              {:attribs=>
                {:major_version=>"14",
                 :minor_version=>"3",
                 :major_build_number=>"158",
                 :minor_build_number=>"11",
                 :version=>"Exchange2010_SP2"}}}]}},
       {:body=>
         {:elems=>
           [{:find_item_response=>{:elems=>[{:response_messages=>{}}]}}]}}]}}>
mojobiri commented 7 years ago

+1 @jcarbo