From 89444d40a40b8bab0fe7f16cb6badb6d8bb061b4 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Thu, 9 Jun 2011 07:10:28 +0000 Subject: Added better error processing for loaded Lua code --- provisioning-model.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'provisioning-model.lua') diff --git a/provisioning-model.lua b/provisioning-model.lua index bb68af6..8a24545 100644 --- a/provisioning-model.lua +++ b/provisioning-model.lua @@ -246,8 +246,14 @@ validateparamcoded = function(p, top) setfenv (0, env) local f = loadstring(p.validate) if (f) then - p.value, p.errtxt = f(p.value, functions, top) - if p.errtxt then success = false end + local res, err = pcall(function() + p.value, p.errtxt = f(p.value, functions, top) + if p.errtxt then success = false end + end) + if not res and err then + success = false + p.errtxt = "Exception in validate code\n"..err + end end setfenv (0, _G) end @@ -261,7 +267,14 @@ local function callscript(script, ...) -- so we set env 0, not env 1 setfenv (0, env) local f = loadfile(script) - if (f) then f(functions, ...) end + if f then + local res, err = pcall(function(...) + f(functions, ...) + end, ...) + if not res and err then + assert(res, "Update Successful\nException in post update script\n"..err) + end + end setfenv (0, _G) end -- cgit v1.2.3