diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-20 17:23:49 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-10-20 17:23:49 +0300 |
| commit | 1a9389f0687017430c84ade3252f46ac4b77a738 (patch) | |
| tree | 3e2ebccfa96d1176f730fcbc1d8f94414b5f068d /src | |
| parent | 20362f98249c1599c314562c8efb3a69bfd2017f (diff) | |
| download | luarocks-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.lua | 24 |
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. |
| 3 | local command_line = {} | 3 | local command_line = {} |
| 4 | 4 | ||
| 5 | local pack = function(...) return {...}, select("#", ...) end | ||
| 5 | local unpack = unpack or table.unpack | 6 | local unpack = unpack or table.unpack |
| 6 | 7 | ||
| 7 | local util = require("luarocks.util") | 8 | local util = require("luarocks.util") |
| @@ -13,17 +14,24 @@ local fs = require("luarocks.fs") | |||
| 13 | 14 | ||
| 14 | local program = util.this_program("luarocks") | 15 | local program = util.this_program("luarocks") |
| 15 | 16 | ||
| 17 | local 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) | ||
| 20 | end | ||
| 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 |
| 19 | local function die(message, exitcode) | 25 | local 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) |
| 28 | end | 36 | end |
| 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 |
