Wednesday, August 17, 2005

Bad error messages

Error: can not locate file....

What am I supposed to gain from reading that message? Any information at all would help. What file? I know the program must know what file it tried. Why the ellipsis and the "Error: " string? This error resulted from a failed stat call, which normally means the file doesn't exist. But what if it were a permissions problem or a self-reference symlink or the path argument exceeded PATH_MAX? That's why we have errno and strerror.

Fortunately I had access to the source and changed it to:

Can not stat /path/to/file: No such file or directory

The orignal code made this more difficult by using this custom function:

int error_msg(char *error)

I know varags is a pain, but it really does have a place. There is no reason error messages can't provide more than enough information to debug any problem.

No comments: