From 66683f6d13cde8dcec9e1f13fb0ae705f3e70cb3 Mon Sep 17 00:00:00 2001 From: HenryDu8133 <813367384@qq.com> Date: Sun, 16 Aug 2026 14:23:43 +0800 Subject: [PATCH] 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 --- station_broadcast.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/station_broadcast.lua b/station_broadcast.lua index 01f4fb7..788b0df 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -1,6 +1,6 @@ -- 1. Configuration & Constants -local APP_VERSION_TEXT = "v1.0.74" +local APP_VERSION_TEXT = "v1.0.75" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -3401,6 +3401,10 @@ function Main.loop() if Peripherals.blockReader then 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 not State.lastRefreshed or State.lastRefreshed ~= data.LastRefreshed 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) 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 if st then local trainName = st.TrainName or "Unknown" @@ -3440,11 +3445,8 @@ function Main.loop() local lastStopover = stop.Stopovers[#stop.Stopovers] if looksLikeValidDestinationText(lastStopover) then destination = lastStopover - else - if looksLikeValidDestinationText(destination) then - else - destination = lastStopover or destination - end + elseif not looksLikeValidDestinationText(destination) then + destination = lastStopover or destination end end @@ -3596,6 +3598,10 @@ function Main.loop() end end end + end) + if not okStop then + Utils.log("WARN", "TrainStop[" .. tostring(i) .. "] parse error: " .. tostring(err)) + end end for k, _ in pairs(State.pendingAlerts) do @@ -3612,7 +3618,10 @@ function Main.loop() end 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 seenApproachKeys = {}