• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Error Messages

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.​

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:

162098-albums5402-picture69574.png


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:

[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:

162098-albums5402-picture69573.png

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.​

~Magtheridon96
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
You can omit the library, just print the full path of the function. Also I would reduce the indication of the warning/error nature to the color or an abbreviation. You often need space for parameters. Or append the line number of an exported logfile for further information to look up. In any way, how about using a debug library?
 
You can omit the library, just print the full path of the function. Also I would reduce the indication of the warning/error nature to the color or an abbreviation. You often need space for parameters. Or append the line number of an exported logfile for further information to look up. In any way, how about using a debug library?

Well, yeah, you can omit the library. You're right about the reduction of the Error/Warning indicator. I guess the color would be enough ;)

As for the debug library suggestion, yes, that's perfectly plausible. We can write one and combine it with a Logger like the one Almia wrote. It would put whatever needs to be said in the correct format.
Not sure who has the will-power to do that though :p. If someone can make a Debug Utility library with proper printError and printWarning functions that takes a source function name and a message, that would be awesome. What would be cooler is if the library ALSO logged the messages to a file.

I'll update this when I can.
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
I dont know if this helps but did you know that putting thistype to string will make it rewriten to the struct name?

JASS:
struct MyStruct
    static method something takes nothing returns nothing
        call BJDebugMsg("struct thistype, method something: error calling")
    endmethod
endstruct

will result in:
struct MyStruct, method something: error calling
 
Top