AgentFeeble / pgoapi

A Pokèmon Go API written in swift.
17 stars 3 forks source link

Index out of range in parseSubResponses #6

Closed beeb closed 8 years ago

beeb commented 8 years ago

Hey there,

I sometimes get an index out of range error on line 46 of ApiResponseDataConverter.swift:

let (requestType, converter) = subResponseConverters[idx]

Do you also encounter this error sometimes?

AgentFeeble commented 8 years ago

I haven't seen that issue come up for me, do you know how to reproduce it? Does it always happen on the same requests? And could you check what request types are in subResponseConverters, and how many elements are response.returns array when you experience the crash?

beeb commented 8 years ago

Haven't been able to reproduce yet but if it happens again I will be able to provide this information.

AgentFeeble commented 8 years ago

I actually managed to reproduce this today, but unfortunately it was while the debugger wasn't connected 😕. I've implemented a fix that should stop it from crashing, at the expense of not returning all the data if this does happen. I'll only get a chance to push it later though, I'm not at my computer right now

beeb commented 8 years ago

Alright I implemented a similar fix myself (with a condition to print the problematic data if the index of out of range), I'll report if I see something.

beeb commented 8 years ago

Got the error again. subResponseConverters had 1 entry:

[(.GetMapObjects, pgoapi.ProtoBufDataConverter<ProtocolBuffers.GeneratedMessage>(convertFunc: (Function)))]

while response.returns had 2 elements

AgentFeeble commented 8 years ago

Were you requesting anything other than the map objects? If not, it looks like the server is returning extra data not requested by the client. As long as the extra data is after the map object data in the array we should be fine to just ignore the unnecessary supplemental data.

beeb commented 8 years ago

I confirm I was only requesting map objects, I think you're right and the additional condition is sufficient to prevent the runtime error.

AgentFeeble commented 8 years ago

I'm going to assume the extra data is at the end of the array, and close this issue for now. We can reopen it if anything comes up to suggest otherwise.

Fixed in 4fe043accc8d459c5c60f3437bcecec8d3dd8ca6. Thanks for the help tracking this down 👍