Hello. I have been struggling with detecting errors in my code. Debug does not work, as these types of bugs are 80% not happening, and 20% they happen, and I never get to see the error. I have been spammed by my lovely visitors that a bug is there and there, but most of the time when I test it or some of my QA tester, we never get to know the error.
The idea i am talking about; once an error happens, save it to database.
"I do not want to use pcall or any kind of protected calls, as I do not feel like putting pcall to every line of a code with 1000 lines.
So I came up if this idea could work. At this point I am willing for any option, even if I would need to make a plugin, etc. Nowhere, youtube, google and devforum, I could not find anything.
When you say saving to a database, are you referring to Roblox or external? I would highly advise not using something like Discord webhooks to log errors (not implying you would, it just seems to be a lot of peoples first option).
Anyways, onto the question. If you want to avoid using pcalls and simply want something to get the error message, I’m pretty sure you can do this pretty simply with the following:
local LS = game:GetService("LogService")
LS.MessageOut:Connect(function(Message, Type)
if Type == Enum.MessageType.MessageError then
print("Error detected! The error was "..Message)
end
end)
As for logging it, you can use Sentry or something like that to do so. There’s some pretty good modules out there for Sentry that make using it in correlation to your Roblox game simple.
Thank you. I use datastore service because as you said, discord can not be used. Also, is there a way I could get the script the error happened in? Or is this function supposed to be in the script which I want to monitor?
Thank you for this, I was hoping for something like a service, there is still lots of things I possible am not aware of.
This will log for every script yes. Hmm, I’m actually not too sure how you’d be able to get the script this happened in. One method I can think off right off the bat is just also just logging Enum.MessageType.MessageInfo, but this will log for any MessageInfo, not just error message info. What you could do, and keep in mind this is a very hacky method that isn’t preferred, is detect the previous MessageType, if it was of type ErrorMessage, you could print out the MessageInfo that came along with it and match it to a string. Here’s an example:
local LS = game:GetService("LogService")
local Previous
LS.MessageOut:Connect(function(Message, Type)
if Type ~= Enum.MessageType.MessageInfo then -- errors send like 3 different messages which are message info, meaning to get the script this occurred in we need to add this.
Previous = Type
if Type == Enum.MessageType.MessageError then
print("Error detected! The message was "..Message)
end
end
if Previous == Enum.MessageType.MessageError then
if string.match(Message, "Line") then
print("Error info: "..Message) --an example of what this would print is: "Error info: Script 'ServerScriptService.Script', Line 1 "
end
end
end)
I know, a very hacky method indeed, but it’s all I can think of regarding this to be honest without directly knowing the script name and having this work globally. Also even Roblox datastores might not be the best option (depending on how many errors you have of course). I’d recommend concatenating both the string.match(“line”) message with the actual MessageError so it’s all in one place, or maybe doing so and storing it in a table, and then just saving that table on a :BindToClose