1

In my code I often need to differentiate between messages intended for logging and those displayed to users. I'm looking for a terse term for naming variables and methods that indicates a user-readable message. I've tried "userReadable", "userVisible", etc, but they all feel too verbose, especially when combined with more details like "fileUserReadableError".

E.g:

fileLogError = "Error 123 occurred writing file /x/y/z";
fileUserReadableError = "We couldn't save your kitty picture, sorry";

Is there a better term? The latter especially is a mouthful (fingerful, whatever)

0

1 Answer 1

1

Based on your sparse description the two errors can be internally identical with the difference being made by the locus of catching. To be more concrete:

def write_photo(photo, path):
    try:
       open(path, 'w')     # can throw OSError
       ...
    except OSError:
       logging.error("cannot write path", path)
       raise

def save_kitten(kitten):
    try:
        write_photo(kitten, '/x/y/z')
    except OSError:
        print('We couldn't save your kitty picture, sorry')

Obviously this model is Python-like because it has a well constructed exception mechanism. But you can read it as pseudo-code. The point is that there are two levels of operation, the internal (write_photo) and the user facing (save_kitten). The same error can be interpreted in two different ways depending upon what level the fault happens at. The concept of logging and re-raising allows one fault to be handled at two different levels of description.

Implicit here is that the fault really doesn't change its contents; the lone raise just re-throws the same exception. But the same fault does have different interpretations which are a feature of the level of detection. Adding another error type is needlessly redundant when each level knows who it is communicating with.

1
  • I've updated my question with more details. I'm not looking for an answer to a specific problem. This is a question about the best terminology to use when naming variables and methods. May 30, 2016 at 17:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.