From 1a9389f0687017430c84ade3252f46ac4b77a738 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Thu, 20 Oct 2016 17:23:49 +0300 Subject: Show traceback for errors in scheduled functions --- src/luarocks/command_line.lua | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'src') 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 @@ --- Functions for command-line scripts. local command_line = {} +local pack = function(...) return {...}, select("#", ...) end local unpack = unpack or table.unpack local util = require("luarocks.util") @@ -13,17 +14,24 @@ local fs = require("luarocks.fs") local program = util.this_program("luarocks") +local function error_handler(err) + return debug.traceback("LuaRocks "..cfg.program_version.. + " bug (please report at https://github.com/keplerproject/luarocks/issues).\n"..err, 2) +end + --- Display an error message and exit. -- @param message string: The error message. -- @param exitcode number: the exitcode to use local function die(message, exitcode) assert(type(message) == "string") + util.printerr("\nError: "..message) - local ok, err = pcall(util.run_scheduled_functions) + local ok, err = xpcall(util.run_scheduled_functions, error_handler) if not ok then - util.printerr("\nLuaRocks "..cfg.program_version.." internal bug (please report at https://github.com/keplerproject/luarocks/issues):\n"..err) + util.printerr("\nError: "..err) + exitcode = cfg.errorcodes.CRASH end - util.printerr("\nError: "..message) + os.exit(exitcode or cfg.errorcodes.UNSPECIFIED) end @@ -177,12 +185,10 @@ function command_line.run_command(...) if commands[command] then local cmd = require(commands[command]) - local xp, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, function(err) - die(debug.traceback("LuaRocks "..cfg.program_version - .." bug (please report at https://github.com/keplerproject/luarocks/issues).\n" - ..err, 2), cfg.errorcodes.CRASH) - end) - if xp and (not ok) then + local call_ok, ok, err, exitcode = xpcall(function() return cmd.command(flags, unpack(nonflags)) end, error_handler) + if not call_ok then + die(ok, cfg.errorcodes.CRASH) + elseif not ok then die(err, exitcode) end else -- cgit v1.2.3-55-g6feb