josefnpat / vapor

Vapor - LÖVE Distribution Client
zlib License
77 stars 24 forks source link

Vapor crashes on attempt update game.json when offline #96

Closed Yonaba closed 11 years ago

Yonaba commented 11 years ago

In case Vapor was already run once (and game.json along with some other data) was saved, and then after, Vapor is executed again, but being offline, it crashes on trying to update game.json.

The problem lies in src/core/remote.lua in function remote.load. Since it always receives no arg from main.lua, force_local is always nil. Then, the condition:

  if not force_local then
    r,e = http.request(remote.uri)
  end

is traversed, and then http.request fails, of course.

A possible workaround can be making use of pcall:

local r, e, success
if not force_local then
  success, r,e = pcall(http.request,remote.uri)
  if not success then
    -- Custom : we can either throw an error, or better, 
    -- let the program run and print on ui that there was some
    -- issue trying to update game.json, and therefore the content 
    -- shown might not be up-to-date...
  end
end

But I believe that this would shadow the possible use of force_local (maybe meant for debugging). An alternative way (which can be mixed with the previous) would be adding some custom function in main.lua to check for connection, and set a boolean accordingly that will be passed to remote.load.

local running_local = isRunningLocal(...)
remote.load(running_local)

The running_localarg will behave as force_local in src/core/remote.lua. As I am not familiar (at all) with LuaSocket and internet stuff, I won't implement it myself, otherwise I would have sent a proper pull request.

Sorry for being that long.

Regards, Roland.

josefnpat commented 11 years ago

FEATURE AS INTENDED ... WE MUST WATCH YOU PLAY YOUR GAMES ~NSA

But seriously, this is a bug, I didn't think http.request would throw an error when the internet wasn't accessible, which is why I only ever checked it against if e == 200 then.

Thank you, I will get this fixed asap!

josefnpat commented 11 years ago

I cloned the repo on my laptop, and recreated the issue by disabling the wireless.

Commit cf36937eb59586847cb759973e479f1d5ffa3e4b seems to fix this problem, @Yonaba please tell me if this fixes it for you as well!

Close if we're golden.

Yonaba commented 11 years ago

We're golden. :+1: