When I first started working on my game, which isn’t released yet (but close to) I didn’t design it with error catching in mind because I’m was new to scripting at this point and it didn’t occur to me that it’d be very useful on release. More lately, I’ve been wanting to design a system that catches every single error, and saves it to an “Error” DataStore so I can look at them when the game releases and I can fix them accordingly.
Is there any way to make a script sorta read the output and see an error and handle it accordingly? Or will I need to do pcall in every single script that currently exists in my game.
If you are literally using DataStores for errors, don’t. You deplete your budget for no good reason and you have little control over when calls are made to log errors. Repro bugs and fix them yourself.
You can use to use LogService to read lines sent to the console. There’s also the option of logging some calls to external servers, such as Sentry, to track errors.
Don’t pcall all your code because that’s bad use of a pcall.
I’ll research other ways of saving/tracking the errors then, rather than a DataStore. I’m doing this as a more reliable way of finding out about bugs that I miss on release. Thanks for telling me about the service, it’s exactly what I’m looking for!
You can use the “ScriptContext.Error” event: it gets fired every time an error happens in a script of any kind (see ScriptContext | Documentation - Roblox Creator Hub). It can be used on both client and server side, and is useful because it contains the stack trace of the error and tells you what script had the error. To save errors, you could set up a system where every time this event is fired, that error is saved to a datastore (as you described). However, if you had many errors (such as errors that occurred on Heartbeat), this would be expensive and very likely drain all of your datastore budget. So, I would recommend batching errors together, separating them with some delimiter, and uploading the delimited batch into the datastore. Later, when you retrieve the data, you can parse it from a batch of errors back into individual errors b/c you know what the delimiter is. This way, you can have all your errors to look at later without running out of datastore requests.