- Joined
- Dec 12, 2008
- Messages
- 7,385
Error and Warning Messages in Public Libraries
Introduction
In this mini-tutorial, I will be discussing proper Error and Warning messages.
This is something a lot of people get wrong and I'm sick and tired of it, so I'll
be showing you how to make proper error/warning messages that make sense.
This is something a lot of people get wrong and I'm sick and tired of it, so I'll
be showing you how to make proper error/warning messages that make sense.
Problem
In many of the libraries I find crawling this website, I see very ambiguous
error messages that would make no sense in game or be any helpful.
Consider the following in-game screenshot:
Do those error messages seem helpful at all? Does the first one mention a spell?
Do any of them mention where the errors/warnings are popping up? In a large
map, how would I know where to look in my code when I'm getting meaningless
errors popping up and filling my screen? How would I know if what I'm getting is
an error or a warning? These debug messages are creating problems, not solving
them.
error messages that would make no sense in game or be any helpful.
Consider the following in-game screenshot:
Do those error messages seem helpful at all? Does the first one mention a spell?
Do any of them mention where the errors/warnings are popping up? In a large
map, how would I know where to look in my code when I'm getting meaningless
errors popping up and filling my screen? How would I know if what I'm getting is
an error or a warning? These debug messages are creating problems, not solving
them.
Solution
My solution to this problem is to standardize error/warning messages. Personally,
I use the following format:
Key:
Following the above convention, this is what debugging would look like:
I use the following format:
[Library] [Function] Type: Description
Key:
- Library: This is the name of the Library or the package. In vJASS, you would
use the name of the library in the header or the scope name. In JASS, you would
use the name of the resource or the trigger that it's in. (Either way, this should
not cause ambiguity problems because in vJASS, it is commonplace, and even
expected of a user to use the library name as the trigger name.) - Function: This is the name of the function or the static struct method in which
the error is. In the case where you have a method, you would also display the
instance like this: [(Instance).Method] where "Instance" is the integer that
represents the instance of the struct and Method represents the method name. - Type: This is either "Error" or "Warning".
- Description: This is where you briefly explain what's going on.
Following the above convention, this is what debugging would look like:
Conclusion
This kind of formatting in error messages allows us to find the origin of
bugs in our code. It allows us to debug maps faster and spot bugs easier.
It's also important to make the distinction between a Warning and an Error.
When it's an error, something went wrong and it should be looked at, but
when it's a warning, something was done incorrectly but it was handled
accordingly and it should be looked at. Another nice thing to do is to color
them as I did in the screenshot.
Stay in school, don't do drugs and all that.
bugs in our code. It allows us to debug maps faster and spot bugs easier.
It's also important to make the distinction between a Warning and an Error.
When it's an error, something went wrong and it should be looked at, but
when it's a warning, something was done incorrectly but it was handled
accordingly and it should be looked at. Another nice thing to do is to color
them as I did in the screenshot.
Stay in school, don't do drugs and all that.
~Magtheridon96