-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrorHandling.lua
More file actions
37 lines (29 loc) · 1.04 KB
/
Copy patherrorHandling.lua
File metadata and controls
37 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
local callingFileInfo = nil
local commandInfo = nil
local warnStateCreated = false
local function warn(message)
if callingFileInfo and commandInfo and not warnStateCreated then
io.stderr:write("\nwarning(s) while attempting to "..commandInfo.." "..callingFileInfo..":\n")
warnStateCreated = true
end
io.stderr:write((warnStateCreated and " - " or "")..message.."\n")
end
local function wrapWithErrorHandling(func, stepName)
return function (...)
local debugInfo = debug.getinfo(2, "Sl")
callingFileInfo = debugInfo.source.."(line "..debugInfo.currentline..")"
commandInfo = stepName.." ("..table.concat({...}, ", ")..")"
local status, result = pcall(func, ...)
if not status then
error("error when attempting to "..commandInfo.." "..callingFileInfo..":\n"..result)
end
callingFileInfo = nil
commandInfo = nil
warnStateCreated = false
return result
end
end
return {
warn = warn,
wrapWithErrorHandling = wrapWithErrorHandling
}