Skip to content

Instantly share code, notes, and snippets.

@Fingercomp
Created December 11, 2016 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fingercomp/6563c64d70a4472f26923f78d77caeb9 to your computer and use it in GitHub Desktop.
Save Fingercomp/6563c64d70a4472f26923f78d77caeb9 to your computer and use it in GitHub Desktop.
local shell = require("shell")
local fs = require("filesystem")
local args = {...}
local elog = shell.resolve(table.remove(args, 1))
local path = shell.resolve(table.remove(args, 1))
if not elog or not path then
print("USAGE: crash <error log path> <path to program> [arguments...]")
return 1
end
if not fs.exists(path) or fs.isDirectory(path) then
print("Invalid path.")
print("USAGE: crash <error log path> <path to program> [arguments...]")
return 1
end
if not fs.exists(fs.path(elog)) then
fs.makeDirectory(fs.path(elog))
end
local result = {xpcall(loadfile(path), debug.traceback, table.unpack(args))}
if result[1] then
return table.unpack(result, 2)
else
print("Program crashed.")
local file = io.open(elog, "w")
file:write(result[2])
file:close()
print("Error log saved to: " .. elog)
return 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment