Saturday, December 1, 2012

Standard Error Output

Command line error messages should be sent to the standard error channel; the Qt qWarning() function should not be used because these messages can be disabled.  The cout() function was modified to accept a FILE stream (channel) pointer, either stdout or stderr, with stdout the default.  The qWarning() calls were changed to cout(stderr), which made these lines cleaner because the qPrintable() function is not longer needed to output QString values.

There was also a qWarning() call in the Tester run function when table errors are detected.  These only occur when there are problems in the table entries and are followed by a qFatal() call (which terminates the program).  This qWarning() call was changed to a qCritical() call, whose messages can not be disabled.

Previously, to get the usage message, invalid arguments had to be specified.  To get the usage message without returning an error, new help options were added (either '-?' or '-h').  The usage message will be output to standard output channel when using these options, but to the standard error channel for invalid arguments.

When an error occurs in the Tester run function, like when the test file can't be opened, the standard output channel needs to be closed and the standard error channel opened to output the error message.  The new function coutClose() was added to the CommandLine class, which closes the current channel (if open), which is called before outputting the error message from the Tester instance.  The code for this function was pulled from the destructor, which was replaced with a call to the new function.

[commit e64eadee4a]

Returning Command Line Errors

When the starting of the single shot time to force the application to quit upon entering the event loop was replaced by a simple return (of 0), I realized that it should really be returning an error code if there is an error in the command line options.

To accomplish this, the processed flag in the CommandLine class was replaced with return code variable, which has three values: 0 for successfully processed command line only option, 1 for error occurred with the command line options, and -1 for no command line only options (in other words, start the GUI).  An access function was added for the return code.

The processed access function remains (so callers don't need to be modified), but now returns true if the return code variable is not negative.  A return code variable was also added to the MainWindow class along with an access function.  In the constructor, the return code is obtained from the command line instance when the GUI active flag is set to false (when the command line was processed).  The main function was modified to return this code.

By convention, a command returns a code of 0 to indicate success and any other value to indicate an error.  Some commands return a specific error code value, but here just a general error occurred code (1) is returned.  To test if this new functionality was working correctly, this command was used:
ibcp -v && echo no error
This command will output the version number followed by the "no error" message.  If the -v is replaced with an invalid option, the "no error" message will not be output.

[commit 164fb19fe8]