fix(upcoming): prevent UPCOMING freeze caused by NBT parsing errors in CC environment
- Eliminate empty-then block in Stopovers fallback logic: rewrite nested if/else with empty body to elseif chain to avoid parser error in reduced CC Lua dialect (was silently caught by pcall causing newUpcoming to remain empty) - Add pcall protection to the standalone CreateTarget.dump() path (previously unprotected), with fallback to empty lines table on failure - Add explicit WARN log on BlockReader.getBlockData pcall failure so user can diagnose errors via terminal output instead of silent data=nil - Wrap each TrainStop iteration inside its own pcall so a malformed entry cannot abort the whole loop; failures are logged with stop index Bump to v1.0.75
This commit is contained in:
+15
-6
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
-- 1. Configuration & Constants
|
-- 1. Configuration & Constants
|
||||||
local APP_VERSION_TEXT = "v1.0.74"
|
local APP_VERSION_TEXT = "v1.0.75"
|
||||||
|
|
||||||
local CONFIG = {
|
local CONFIG = {
|
||||||
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
CLOUD_URL = "ws://stabadmin.fse-media.group",
|
||||||
@@ -3401,6 +3401,10 @@ function Main.loop()
|
|||||||
|
|
||||||
if Peripherals.blockReader then
|
if Peripherals.blockReader then
|
||||||
local ok, data = pcall(Peripherals.blockReader.getBlockData)
|
local ok, data = pcall(Peripherals.blockReader.getBlockData)
|
||||||
|
if not ok then
|
||||||
|
Utils.log("WARN", "BlockReader.getBlockData() failed: " .. tostring(data))
|
||||||
|
data = nil
|
||||||
|
end
|
||||||
if ok and data and data.TrainStops then
|
if ok and data and data.TrainStops then
|
||||||
if not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed then
|
if not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed then
|
||||||
if State.lastRefreshed and State.lastRefreshedEpoch then
|
if State.lastRefreshed and State.lastRefreshedEpoch then
|
||||||
@@ -3426,6 +3430,7 @@ function Main.loop()
|
|||||||
cleanupTimestampMap(State.announcedAlerts, now, tonumber(CONFIG.ALERT_COOLDOWN_MS) or 300000)
|
cleanupTimestampMap(State.announcedAlerts, now, tonumber(CONFIG.ALERT_COOLDOWN_MS) or 300000)
|
||||||
|
|
||||||
for i, stop in ipairs(data.TrainStops) do
|
for i, stop in ipairs(data.TrainStops) do
|
||||||
|
local okStop, err = pcall(function()
|
||||||
local st = type(stop.Station) == "table" and stop.Station[1] or stop.Station
|
local st = type(stop.Station) == "table" and stop.Station[1] or stop.Station
|
||||||
if st then
|
if st then
|
||||||
local trainName = st.TrainName or "Unknown"
|
local trainName = st.TrainName or "Unknown"
|
||||||
@@ -3440,13 +3445,10 @@ function Main.loop()
|
|||||||
local lastStopover = stop.Stopovers[#stop.Stopovers]
|
local lastStopover = stop.Stopovers[#stop.Stopovers]
|
||||||
if looksLikeValidDestinationText(lastStopover) then
|
if looksLikeValidDestinationText(lastStopover) then
|
||||||
destination = lastStopover
|
destination = lastStopover
|
||||||
else
|
elseif not looksLikeValidDestinationText(destination) then
|
||||||
if looksLikeValidDestinationText(destination) then
|
|
||||||
else
|
|
||||||
destination = lastStopover or destination
|
destination = lastStopover or destination
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if not looksLikeValidDestinationText(destination) and isLast then
|
if not looksLikeValidDestinationText(destination) and isLast then
|
||||||
if looksLikeValidDestinationText(rtStationName) then
|
if looksLikeValidDestinationText(rtStationName) then
|
||||||
@@ -3596,6 +3598,10 @@ function Main.loop()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
if not okStop then
|
||||||
|
Utils.log("WARN", "TrainStop[" .. tostring(i) .. "] parse error: " .. tostring(err))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for k, _ in pairs(State.pendingAlerts) do
|
for k, _ in pairs(State.pendingAlerts) do
|
||||||
@@ -3612,7 +3618,10 @@ function Main.loop()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not Peripherals.blockReader and Peripherals.createTarget then
|
if not Peripherals.blockReader and Peripherals.createTarget then
|
||||||
local lines = Peripherals.createTarget.dump()
|
local okCT, lines = pcall(Peripherals.createTarget.dump)
|
||||||
|
if not okCT or type(lines) ~= "table" then
|
||||||
|
lines = {}
|
||||||
|
end
|
||||||
local seenAlertKeys = {}
|
local seenAlertKeys = {}
|
||||||
local seenApproachKeys = {}
|
local seenApproachKeys = {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user