Skip to content

Commit cfa64f7

Browse files
committed
Added error catching for user-side scripts so it can't bring down the entire control menu
1 parent 227811d commit cfa64f7

File tree

1 file changed

+16
-11
lines changed
  • DCS-Keybind-Injector-Quaggles/DCS-Keybind-Injector-Quaggles/Scripts/Input

1 file changed

+16
-11
lines changed

DCS-Keybind-Injector-Quaggles/DCS-Keybind-Injector-Quaggles/Scripts/Input/Data.lua

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,23 @@ local function QuagglesKeybindInjector(filename, folder, env, result)
102102
if lfs.attributes(newFileName) then
103103
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '----Found merge at: '..newFileName) end
104104
--Configure file to run in same environment as the default command entry file
105-
local f = loadfile(newFileName)
106-
setfenv(f, env)
107-
local statusInj, resultInj
108-
statusInj, resultInj = pcall(f)
109-
110-
-- Merge resulting tables
111-
if statusInj then
112-
if resultInj.keyCommands then env.join(result.keyCommands, resultInj.keyCommands) end
113-
if resultInj.axisCommands then env.join(result.axisCommands, resultInj.axisCommands) end
114-
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge successful') end
105+
local f, err = loadfile(newFileName)
106+
if err ~= nil then
107+
log.write(quagglesLogName, log.ERROR, '------Failure loading: '..tostring(newFileName).." Error: "..tostring(err))
108+
return
115109
else
116-
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge failed: '..tostring(statusInj)) end
110+
setfenv(f, env)
111+
local statusInj, resultInj
112+
statusInj, resultInj = pcall(f)
113+
114+
-- Merge resulting tables
115+
if statusInj then
116+
if resultInj.keyCommands then env.join(result.keyCommands, resultInj.keyCommands) end
117+
if resultInj.axisCommands then env.join(result.axisCommands, resultInj.axisCommands) end
118+
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge successful') end
119+
else
120+
if quagglesLoggingEnabled then log.write(quagglesLogName, log.INFO, '------Merge failed: '..tostring(statusInj)) end
121+
end
117122
end
118123
end
119124
end

0 commit comments

Comments
 (0)