aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Melnichenko <mpeterval@gmail.com>2016-10-20 17:23:49 +0300
committerPeter Melnichenko <mpeterval@gmail.com>2016-10-20 17:23:49 +0300
commit1a9389f0687017430c84ade3252f46ac4b77a738 (patch)
tree3e2ebccfa96d1176f730fcbc1d8f94414b5f068d /src
parent20362f98249c1599c314562c8efb3a69bfd2017f (diff)
downloadluarocks-1a9389f0687017430c84ade3252f46ac4b77a738.tar.gz
luarocks-1a9389f0687017430c84ade3252f46ac4b77a738.tar.bz2
luarocks-1a9389f0687017430c84ade3252f46ac4b77a738.zip
Show traceback for errors in scheduled functions
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/command_line.lua24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua
index 1a8c0fe7..858e871f 100644
--- a/src/luarocks/command_line.lua
+++ b/src/luarocks/command_line.lua
@@ -2,6 +2,7 @@
2--- Functions for command-line scripts. 2--- Functions for command-line scripts.
3local command_line = {} 3local command_line = {}
4 4
5local pack = function(...) return {...}, select("#", ...) end
5local unpack = unpack or table.unpack 6local unpack = unpack or table.unpack
6 7
7local util = require("luarocks.util") 8local util = require("luarocks.util")
@@ -13,17 +14,24 @@ local fs = require("luarocks.fs")
13 14
14local program = util.this_program("luarocks") 15local program = util.this_program("luarocks")
15 16
17local function error_handler(err)
18 return debug.traceback("LuaRocks "..cfg.program_version..
19 " bug (please report at https://github.com/keplerproject/luarocks/issues).\n"..err, 2)
20end
21
16--- Display an error message and exit. 22--- Display an error message and exit.
17-- @param message string: The error message. 23-- @param message string: The error message.
18-- @param exitcode number: the exitcode to use 24-- @param exitcode number: the exitcode to use
19local function die(message, exitcode) 25local function die(message, exitcode)
20 assert(type(message) == "string") 26 assert(type(message) == "string")
27 util.printerr("\nError: "..message)
21 28
22 local ok, err = pcall(util.run_scheduled_functions) 29 local ok, err = xpcall(util.run_scheduled_functions, error_handler)
23 if not ok then 30 if not ok then
24 util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at https://github.com/keplerproject/luarocks/issues):\n"..err) 31 util.printerr("\nError: "..err)
32 exitcode = cfg.errorcodes.CRASH
25 end 33 end
26 util.printerr("\nError: "..message) 34
27 os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) 35 os.exit(exitcode or cfg.errorcodes.UNSPECIFIED)
28end 36end
29 37
@@ -177,12 +185,10 @@ function command_line.run_command(...)
177 185
178 if commands[command] then 186 if commands[command] then
179 local cmd = require(commands[command]) 187 local cmd = require(commands[command])
180 local xp, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, function(err) 188 local call_ok, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, error_handler)
181 die(debug.traceback("LuaRocks "..cfg.program_version 189 if not call_ok then
182 .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" 190 die(ok, cfg.errorcodes.CRASH)
183 ..err, 2), cfg.errorcodes.CRASH) 191 elseif not ok then
184 end)
185 if xp and (not ok) then
186 die(err, exitcode) 192 die(err, exitcode)
187 end 193 end
188 else 194 else