Skip to content
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

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

Closed
ingnam opened this issue Sep 4, 2019 · 5 comments
Closed

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

ingnam opened this issue Sep 4, 2019 · 5 comments
Labels

Comments

@ingnam
Copy link

ingnam commented Sep 4, 2019

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
Copy link
Owner

@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
Copy link
Author

ingnam commented Sep 11, 2019

@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
Copy link
Owner

hakanensari commented Sep 11, 2019

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
Copy link
Owner

Edited comment☝️ to add test code

@stale
Copy link

stale bot commented Nov 10, 2019

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.

@stale stale bot added the wontfix label Nov 10, 2019
@stale stale bot closed this as completed Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants