lineofflight / peddler

Amazon Selling Partner API (SP-API) in Ruby
https://lineofflight.github.io/peddler/
MIT License
307 stars 130 forks source link

undefined method `key?' for nil:NilClass #137

Closed ingnam closed 4 years ago

ingnam commented 5 years ago

I am using peddler version 1.6.2. When parsing the response, I got following error: undefined method 'key?' for nil:NilClass

And here is the backtrace:

/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/multi_xml-0.6.0/lib/multi_xml/parsers/ox.rb:77:in `append'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/multi_xml-0.6.0/lib/multi_xml/parsers/ox.rb:52:in `text'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/multi_xml-0.6.0/lib/multi_xml/parsers/ox.rb:32:in `sax_parse'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/multi_xml-0.6.0/lib/multi_xml/parsers/ox.rb:32:in `parse'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/multi_xml-0.6.0/lib/multi_xml.rb:146:in `parse'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/peddler-1.6.2/lib/peddler/xml_parser.rb:20:in `xml'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/peddler-1.6.2/lib/peddler/xml_response_parser.rb:16:in `find_data'
/data/channel_manager/shared/bundled_gems/ruby/2.4.0/gems/peddler-1.6.2/lib/]/xml_parser.rb:16:in `parse'

Here is the response:

#<Excon::Response:0x00007f28412f4278
 @body=
  "<?xml version=\"1.0\"?>\n" +
  "<SubmitFeedResponse xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\"><SubmitFeedResult><FeedSubmissionInfo><FeedSubmissionId>78892018141</FeedSubmissionId><FeedType>_POST_INVENTORY_AVAILABILITY_DATA_</FeedType><SubmittedDate>2019-09-02T23:13:55+00:00</SubmittedDate><FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus></FeedSubmissionInfo></SubmitFeedResult><ResponseMetadata><RequestId>f4a33a13-0066-4353-8e0c-87400e4c90b9</RequestId></ResponseMetadata></SubmitFeedResponse>",
 @data=
  {:body=>
    "<?xml version=\"1.0\"?>\n" +
    "<SubmitFeedResponse xmlns=\"http://mws.amazonaws.com/doc/2009-01-01/\"><SubmitFeedResult><FeedSubmissionInfo><FeedSubmissionId>78892018141</FeedSubmissionId><FeedType>_POST_INVENTORY_AVAILABILITY_DATA_</FeedType><SubmittedDate>2019-09-02T23:13:55+00:00</SubmittedDate><FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus></FeedSubmissionInfo></SubmitFeedResult><ResponseMetadata><RequestId>f4a33a13-0066-4353-8e0c-87400e4c90b9</RequestId></ResponseMetadata></SubmitFeedResponse>",
   :cookies=>[],
   :host=>"mws.amazonservices.com.au",
   :headers=>
    {"Server"=>"Server",
     "Date"=>"Mon, 02 Sep 2019 23:13:55 GMT",
     "Content-Type"=>"text/xml",
     "Connection"=>"keep-alive",
     "x-mws-quota-max"=>"30.0",
     "x-mws-quota-remaining"=>"29.0",
     "x-mws-quota-resetsOn"=>"2019-09-02T23:34:00.000Z",
     "x-mws-response-context"=>
      "DXUaGkEubpdGogJBIZVMiztjAL/FAPlbx4xq0ZNRMXs+T3pWgkt8KpGqYhwR7x+J19tY0pm1w7c=, rnkX3dvwE3hg7dVHrLgQQFJqzNvf2TxfeDwLeUGq5xSHrNfnfk2hR3mx1Z3Nqal8dn5PvkUCbn4=",
     "x-amz-request-id"=>"f4a33a13-0066-4353-8e0c-87400e4c90b9",
     "x-mws-request-id"=>"f4a33a13-0066-4353-8e0c-87400e4c90b9",
     "x-mws-timestamp"=>"2019-09-02T23:13:55.636Z",
     "x-amz-rid"=>"0C4H0AT2P032G7GDKS1Y",
     "Vary"=>
      "Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent"},
   :path=>"/",
   :port=>443,
   :status=>200,
   :status_line=>"HTTP/1.1 200 OK\r\n",
   :reason_phrase=>"OK",
   :remote_ip=>"54.240.249.123",
   :local_port=>53258,
   :local_address=>"172.31.127.115"},
 @headers=
  {"Server"=>"Server",
   "Date"=>"Mon, 02 Sep 2019 23:13:55 GMT",
   "Content-Type"=>"text/xml",
   "Connection"=>"keep-alive",
   "x-mws-quota-max"=>"30.0",
   "x-mws-quota-remaining"=>"29.0",
   "x-mws-quota-resetsOn"=>"2019-09-02T23:34:00.000Z",
   "x-mws-response-context"=>
    "DXUaGkEubpdGogJBIZVMiztjAL/FAPlbx4xq0ZNRMXs+T3pWgkt8KpGqYhwR7x+J19tY0pm1w7c=, rnkX3dvwE3hg7dVHrLgQQFJqzNvf2TxfeDwLeUGq5xSHrNfnfk2hR3mx1Z3Nqal8dn5PvkUCbn4=",
   "x-amz-request-id"=>"f4a33a13-0066-4353-8e0c-87400e4c90b9",
   "x-mws-request-id"=>"f4a33a13-0066-4353-8e0c-87400e4c90b9",
   "x-mws-timestamp"=>"2019-09-02T23:13:55.636Z",
   "x-amz-rid"=>"0C4H0AT2P032G7GDKS1Y",
   "Vary"=>"Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent"},
 @local_address="172.31.127.115",
 @local_port=53258,
 @remote_ip="54.240.249.123",
 @status=200>

Is it due to older version of the gem?

hakanensari commented 5 years ago

@ingnam, I can't reproduce this error. My hunch is that this does not have to do with Peddler; the parser has no recent changes. Perhaps you could try bumping up Ox?

ingnam commented 5 years ago

@hakanensari, I'm doing more investigation on this but one thing that I've figured out is this issue can be reproduced with the invalid xml format: MultiXml.parse("<?xml version=\"1.0\"?>\n></xml>")

Not sure who should handle it; peddler or multi_xml.

hakanensari commented 5 years ago

I copy-pasted the XML body in your first post into a test. It seems to parse fine, so I’m assuming it's valid? I've also tried against an older Ox gem from 2017 to no avail.

I’m still not quite getting what's happening on your end.

def test_malformed_xml
  body = "<?xml version=\"1.0\"?>\n" \
         '<SubmitFeedResponse xmlns="http://mws.amazonaws.com/doc/2009-01-01/"><SubmitFeedResult><FeedSubmissionInfo><FeedSubmissionId>78892018141</FeedSubmissionId><FeedType>_POST_INVENTORY_AVAILABILITY_DATA_</FeedType><SubmittedDate>2019-09-02T23:13:55+00:00</SubmittedDate><FeedProcessingStatus>_SUBMITTED_</FeedProcessingStatus></FeedSubmissionInfo></SubmitFeedResult><ResponseMetadata><RequestId>f4a33a13-0066-4353-8e0c-87400e4c90b9</RequestId></ResponseMetadata></SubmitFeedResponse>'
  MultiXml.parse(body) # should raise error?
end
hakanensari commented 5 years ago

Edited comment☝️ to add test code

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.