mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
51 lines
1.3 KiB
Lua
51 lines
1.3 KiB
Lua
--
|
|
-- Crash Handler
|
|
--
|
|
|
|
local comms = require("scada-common.comms")
|
|
local log = require("scada-common.log")
|
|
local util = require("scada-common.util")
|
|
|
|
local core = require("graphics.core")
|
|
|
|
local crash = {}
|
|
|
|
local app = "unknown"
|
|
local ver = "v0.0.0"
|
|
local err = ""
|
|
|
|
-- set crash environment
|
|
---@param application string app name
|
|
---@param version string version
|
|
function crash.set_env(application, version)
|
|
app = application
|
|
ver = version
|
|
end
|
|
|
|
-- handle a crash error
|
|
---@param error string error message
|
|
function crash.handler(error)
|
|
err = error
|
|
log.info("=====> FATAL SOFTWARE FAULT <=====")
|
|
log.fatal(error)
|
|
log.info("----------------------------------")
|
|
log.info(util.c("RUNTIME: ", _HOST))
|
|
log.info(util.c("LUA VERSION: ", _VERSION))
|
|
log.info(util.c("APPLICATION: ", app))
|
|
log.info(util.c("FIRMWARE VERSION: ", ver))
|
|
log.info(util.c("COMMS VERSION: ", comms.version))
|
|
log.info(util.c("GRAPHICS VERSION: ", core.version))
|
|
log.info("----------------------------------")
|
|
log.info(debug.traceback("--- begin debug trace ---", 1))
|
|
log.info("--- end debug trace ---")
|
|
end
|
|
|
|
-- final error print on failed xpcall, app exits here
|
|
function crash.exit()
|
|
log.close()
|
|
util.println("fatal error occured in main application:")
|
|
error(err, 0)
|
|
end
|
|
|
|
return crash
|