Harden legacy config file handling

Use the native io.exists helper and return nil when config reads fail instead of raising fatal errors, allowing callers to handle missing or unreadable configuration files gracefully.
This commit is contained in:
L7NEG
2026-09-14 15:42:45 +03:00
parent 96e20e98e1
commit c06a2ff411
+3 -9
View File
@@ -4528,13 +4528,7 @@ function YimConfig(DEFAULT_CONFIG)
}
function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
f:close()
return true
else
return false
end
return io.exists(name)
end
local writeToFile = function(data)
@@ -4575,7 +4569,7 @@ function YimConfig(DEFAULT_CONFIG)
else
config = readFromFile()
if config == nil then
error("[FATAL] Failed to read config file!")
return nil
end
for key, defaultValue in pairs(DEFAULT_CONFIG) do
@@ -4589,7 +4583,7 @@ function YimConfig(DEFAULT_CONFIG)
local readAndDecodeConfig = function()
if not checkAndCreateConfig() then
error("Failed to read config file!", 2)
return nil
end
return readFromFile()
end