Skip to content

Instantly share code, notes, and snippets.

@adrian-alberto
Created July 25, 2015 00:56
Show Gist options
  • Save adrian-alberto/d29f57b21cb1ad24ca70 to your computer and use it in GitHub Desktop.
Save adrian-alberto/d29f57b21cb1ad24ca70 to your computer and use it in GitHub Desktop.
Error Reports to Trello board from ROBLOX
--Don't forget to put a RemoteFunction called SubmitErrorFunction inside of this script object
--TRELLO
local HttpService = game:GetService("HttpService")
local httpEnabled = pcall(function() HttpService:GetAsync("http://httpbin.org/ip", true) end)
local TrelloAPI = {}
--GET THESE FROM TRELLO API
TrelloAPI.key = "KEY"
TrelloAPI.token = "TOKEN"
function TrelloAPI:addCard(name, description, labels, idList)
if not httpEnabled then warn("HttpService is not enabled!") return end
return HttpService:PostAsync("https://api.trello.com/1/cards?key=" .. self.key .. "&token=" .. self.token, HttpService:JSONEncode({
name = name or "",
desc = description or "",
labels = labels,
idList = idList,
}))
end
function TrelloAPI:readList(idList)
local datajson = HttpService:GetAsync("https://api.trello.com/1/lists/" .. idList .. "/cards?key=" .. TrelloAPI.key .. "&token=" .. TrelloAPI.token, true)
--print(datajson)
return HttpService:JSONDecode(datajson)
end
----------------------------------------------------------------------------------------------------------
local ERROR_REPORT_LIST = "LIST ID" --Also get this from trello API
local CACHE = TrelloAPI:readList(ERROR_REPORT_LIST)
--Store with name as error code + message and desc as stackTrace
--Compare stackTrace to prevent duplicates
--Returns error code
function sendErrorReport(message, stackTrace, label)
for i, v in pairs(CACHE) do
local id = tonumber(string.match(v.name, "^ERROR (%d+):") or "0")
if v.desc == stackTrace then
--Error already logged!
return id
end
end
--Doublecheck with a new list
CACHE = TrelloAPI:readList(ERROR_REPORT_LIST)
local error_code = 100
for i, v in pairs(CACHE) do
local id = tonumber(string.match(v.name, "^ERROR (%d+):") or "0")
error_code = math.max(error_code, id)
if v.desc == stackTrace then
--Error already logged!
return id
end
end
--Error hasn't been reported before!
warn("Logging new error!")
error_code = error_code + 1
TrelloAPI:addCard("ERROR " .. error_code .. ": " ..message, stackTrace, {label}, ERROR_REPORT_LIST)
return error_code
end
game:GetService("ScriptContext").Error:connect(function(message, stackTrace, baseScript)
--Server-side errors are purple-labeled
sendErrorReport(message, stackTrace, "purple")
end)
function script.SubmitErrorFunction.OnServerInvoke(player, message, stackTrace)
--Client-side errors are blue-labeled
return sendErrorReport(message, stackTrace, "blue")
end
script.SubmitErrorFunction.Parent = game.ReplicatedStorage
script.LocalErrorReports.Parent = game.StarterPlayer.StarterPlayerScripts
--Put this inside of ErrorReportsTrello
game:GetService("ScriptContext").Error:connect(function(message, stackTrace, baseScript)
game.ReplicatedStorage.SubmitErrorFunction:InvokeServer(message, stackTrace)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment