From a3a3701db6b918cf7b1a1d80705e0ea98371806d Mon Sep 17 00:00:00 2001 From: Dany LE Date: Thu, 9 Apr 2026 17:38:32 +0200 Subject: [PATCH] fix: dont use builtin error function that cause leak unclosed file --- silkmvc/BaseController.lua | 3 +++ silkmvc/BaseObject.lua | 1 - silkmvc/core/hook.lua | 2 +- silkmvc/core/sqlite.lua | 13 +++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/silkmvc/BaseController.lua b/silkmvc/BaseController.lua index b703d67..eff101f 100644 --- a/silkmvc/BaseController.lua +++ b/silkmvc/BaseController.lua @@ -57,17 +57,20 @@ function BaseController:removeSession(key) end function BaseController:index(...) self:error("#index: subclasses responsibility") + return false end -- not found action function BaseController:actionnotfound(...) local args = {...} self:error("#action "..args[1].." is not found in controller "..self.class) + return false end -- not found model function BaseController:modelnotfound(...) local args = {...} self:error("Model "..firstToUpper(args[1]).."Model is not found in controller "..self.class) + return false end -- The not found controller diff --git a/silkmvc/BaseObject.lua b/silkmvc/BaseObject.lua index f1dd233..5009c59 100644 --- a/silkmvc/BaseObject.lua +++ b/silkmvc/BaseObject.lua @@ -32,6 +32,5 @@ function BaseObject:error(msg,...) local emsg = string.format(msg or "ERROR",...) echo(emsg) self:log(Logger.ERROR, msg,...) - error(emsg) return false end \ No newline at end of file diff --git a/silkmvc/core/hook.lua b/silkmvc/core/hook.lua index 0c46449..103671c 100644 --- a/silkmvc/core/hook.lua +++ b/silkmvc/core/hook.lua @@ -96,7 +96,7 @@ function loadscript(file, args) tmp = tmp:sub(y + 1) b, f = tmp:find("<%?=") else - error("Syntax error near line " .. i) + return nil ,"Syntax error near line " .. i end end pro = pro .. "\"" .. utils.escape(tmp, true) .. "\")\n" diff --git a/silkmvc/core/sqlite.lua b/silkmvc/core/sqlite.lua index b2e8114..5e4f592 100644 --- a/silkmvc/core/sqlite.lua +++ b/silkmvc/core/sqlite.lua @@ -110,12 +110,12 @@ end function SQLQueryGenerator:error(msg, ...) local emsg = string.format(msg or "ERROR", ...) LOG_ERROR(msg, ...) - error(emsg) end function SQLQueryGenerator:infer_field(k) if not self.table_name then self:error("Unknown input table (specified by `table_name` field)") + return nil end if not self.joins then return k @@ -135,6 +135,7 @@ function SQLQueryGenerator:sql_joins() local arr = explode(v, ".") if not arr[2] then self:error("SQL JOIN: Other table name parsing error: " .. v) + return nil end table.insert(joins, string.format("INNER JOIN %s ON %s = %s", arr[1], self:infer_field(k), v)) end @@ -159,6 +160,7 @@ function SQLQueryGenerator:sql_order() local arr = explode(v, "$") if #arr ~= 2 then self:error("Invalid field order format %s", v) + return nil end if arr[2] == "asc" then table.insert(tb, self:infer_field(arr[1]) .. " ASC") @@ -166,6 +168,7 @@ function SQLQueryGenerator:sql_order() table.insert(tb, self:infer_field(arr[1]) .. " DESC") else self:error("Unknown order %s", arr[2]) + return nil end end return table.concat(tb, ",") @@ -174,6 +177,7 @@ end function SQLQueryGenerator:sql_where(cond, obj) if not obj then self:error("%s condition is nil", cond) + return nil end local conds = {} local op = " AND " @@ -182,6 +186,7 @@ function SQLQueryGenerator:sql_where(cond, obj) end if type(obj) ~= 'table' then self:error("Invalid input data for operator " .. cond) + return nil end for k, v in pairs(obj) do if k == "$and" or k == "$or" then @@ -203,6 +208,7 @@ end function SQLQueryGenerator:parse_value(v, types) if not types[type(v)] then self:error("Type error: unexpected type %s", type(v)) + return nil end if type(v) == "number" then return tostring(v) @@ -215,6 +221,7 @@ function SQLQueryGenerator:binary(k, v) local arr = explode(k, "$"); if #arr > 2 then self:error("Invalid left hand side format: %s", k) + return nil end if #arr == 2 then if arr[2] == "gt" then @@ -272,6 +279,7 @@ function SQLQueryGenerator:binary(k, v) })) else self:error("Unsupported operator `%s`", arr[2]) + return nil end else return string.format("(%s=%s)", self:infer_field(arr[1]), self:parse_value(v, { @@ -419,7 +427,8 @@ function DBModel:delete(name, cond) local generator = SQLQueryGenerator:new(filter) local r,sql = generator:sql_delete() if not r then - return error(sql) + LOG_ERROR("Error generating delete query: %s", sql) + return false end LOG_DEBUG("Execute query: %s", sql); return self:exec(sql)