Internal error markers

In theory, the end user should never see internal errors. But in practice, theory and practice are different. Therefore, the question is to show the end user. Now, for a completely non-technical user, you want to show as little as possible ("click here to send an error report"), but for more advanced users they will want to know if there is work if it has been known for some time, etc. d. Therefore, you want to include some information about what is wrong.

The classic way to do this is either a statement with a file name: a line number or a stack trace with the same. Now this is good for the developer, because he directly points to the problem; however, it has some significant drawbacks for the user, in particular, that he is very mysterious (for example, unfriendly) and changes to the code change the error message (only Google works for errors for this version).

I have a program that I plan to write where I want to solve these problems. What I want is a way to give a unique identity to each statement in such a way that editing the code around the statement will not change it. (For example, if I cut / paste it into another file, I want the same information to be displayed) Any ideas?

One of the ways I'm thinking about is to list the errors, but how to make sure they are never used in more than one place?

(Note: for this question, I only consider errors caused by coding errors. Not something that can legitimately happen as bad input. OTOH, these errors may be of some interest to the community as a whole.)

(Note 2: the program in question will be a command-line application running on the user system. But then again, this is just my situation.)

(Note 3: the target language is D and I really want to dive into metaprogramming . Answers to other languages ​​are more than welcome!)

(Note 4: I clearly want NOT to use the actual code locations, but rather some symbolic names for errors. This is because if the code changes in almost any way, the code locations change.)

+4
source share
3 answers

Write a script to grep the entire source tree for using these error codes, and then complain about duplicates. Run the script as part of your unit tests.

+1
source

Interest Ask. The solution that I used several times is this: if this is a fatal error (for example, non-fatal errors should give the user the opportunity to correct the input), we will create a file with a lot of relevant information: request variables, headers, internal configuration information and full backtracing for subsequent debugging. We save this in a file with a unique file name generated (and over time as a prefix).

For the user, we present a page explaining that a fatal error has occurred, and ask them to include the file name as a link if they would like to report an error. It is much easier to debug all of this information from the context of the abuse request.

In PHP, the debug_backtrace () function is very useful for this. I am sure there is an equivalent for your platform.

Also remember to send the appropriate http headers: Probably: HTTP / 1.1 500 Internal server error

Given the reasonable format of the error report file, it can also analyze errors that users have not reported.

+2
source

I don’t know anything about your target language, but this is an interesting question that I thought about, and I wanted to add my two cents.

My feeling has always been that reporting hard errors and internal errors should be as helpful as possible to the developer in order to identify the problem and fix it quickly. Most users don’t even look at this error message, but very sophisticated end users (possibly people with technical support) often get a pretty good idea of ​​what the problem is, and even come up with new workarounds by looking at very detailed error messages. The key is to make these error messages detailed without being cryptic, and this is more an art than a science.

An example from a Windows program that uses a COM server outside the processor. If the main program tries to create an instance of the object from the COM server and an error message appears:

"WARNING: Unable to activate UtilityObject: Error 'Class Not Registered' in 'CoCreateInstance'"

99% of users will see this and think that it is written in Greek. A support technician can quickly understand that they need to re-register the COM server. And the developer will definitely understand what went wrong.

In order to associate some contextual information with the statement, in my C ++ code I often use a simple line with the name of the method or something else that makes it clear where the error occurred (I apologize for the answer in a language you are not talking about asked):

int someFunction() { static const std::string loc = "someFunction"; : : if( somethingWentWrong ) { WarningMessage(loc.c_str(), "Unable to Instantiate UtilityObject: Error 'Class Not Registered' in 'CoCreateInstance); } } 

... which generates:

WARNING [someFunction]: cannot complete Activate UtilityObject: "Class not registered" error in "CoCreateInstance

+1
source

All Articles