2010-07-18

Publishing detailed error messages

As an opposition to "Hiding error details". On the input of [Posa1996]1 page 43 (Architectural patterns (2) / Layers (2.2) / Implementation / 10):

Design an error handling strategy. Error handling can be rather expensive for layered architectures with respect to processing time and, notably, programming effort. An error can either be handled in the layer where it occurred or be passed to the next higher layer. In the latter case, the lower layer must transform the error into an error description meaningful to the higher layer. As a rule of thumb, try to handle errors at the lowest layer possible. This prevents higher layers from being swamped with many different errors and voluminous error-handling code. As a minimum, try to condense similar error types into more general error types, and only propagate these more general errors. If you do not do this, higher layers can be confronted with error messages that apply to lower-level abstractions that the higher layer does not understand. And who hasn't seen totally cryptic error messages being popped up to the highest layer of all - the user?

I have to strongly disagree with the author on that point. It is far more worse if the highest layer of all gets an error like "Error." without any details. The error message should be as detailed as possible. Do not be confused! That does not mean that higher layers should not handle these errors in a grouped manner. For example if a file transfer fails on any reason the program logic should abort the transaction, whatever the reason of the failure is, so the so called voluminous error-handling code can be avoided. Not handling but publishing the details of the error can help the user understand and solve the problem. Making distinction between "Directory not found.", "Drive not ready.", and "Permission denied." is very useful at the level of the user (or customer care, product support line, developer, whoever).

Testing, debugging and user support can be a horror without detailed error messages. It can be counted in serious amount of money. If the user does understand the error message then it is an instant win for the user himself/herself and for the customer care both. If he/she doesn't understand then he/she has something to tell at official and unofficial support forums which will bring the solution closer. It is a win-win decision to keep the error messages detailed.

And again, it does not contradict the "keep the volume of error-handling code low" principle. Handling ≠ publishing.

1: [Posa1996] Frank Buschmann et al.: Pattern-oriented software architecture, Volume 1: A system of patterns; © 1996 John Wiley and sons

No comments:

Post a Comment