Fix exit code and error output

Closes issues #252, and also fixes cases where bad syntax in tests would
cause the output handler to explode. Handles bad syntax gracefully now.