Better error handling

This commit is contained in:
2024-07-10 22:52:41 +02:00
parent 43a8ebf800
commit bdc4f51741
4 changed files with 89 additions and 7 deletions

View File

@@ -2,4 +2,5 @@ function love.conf(t)
t.version = "11.4"
t.window.title = "Spider Controller"
t.window.resizable = true
t.window.fullscreen = true
end

View File

@@ -19,9 +19,16 @@ function printTable(table, indentation)
end
end
function safeCall(target, ...)
local success, msg = pcall(target, ...)
if not success then
errorMessage = msg
end
end
function love.draw(...)
if love.draw2 then
love.draw2(...)
if love.draw2 and not errorMessage then
safeCall(love.draw2, ...)
else
local text = "Awaiting payload..."
local font = love.graphics.getFont()
@@ -58,11 +65,11 @@ end
function love.update(...)
local message = mqttEventChannel:pop()
if message then
love.mqtt[message.target](unpack(message.args))
safeCall(love.mqtt[message.target], unpack(message.args))
end
if love.update2 then
love.update2(...)
if love.update2 and not errorMessage then
safeCall(love.update2, ...)
end
end
@@ -78,6 +85,7 @@ end
function love.mqtt.message2(topic, payload)
if topic == "controller/payload" then
errorMessage = nil
local success = love.filesystem.unmount("client.zip")
if not success then
print("Could not unmount client.zip")
@@ -98,7 +106,7 @@ function love.mqtt.message2(topic, payload)
love.load = nil
chunk()
if love.load then
love.load()
safeCall(love.load)
end
elseif love.mqtt.message then
love.mqtt.message(topic, payload)