From ebc6ef1e475209d2f0c0e4aa8fd17a437af80c55 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 5 Mar 2012 20:46:52 +0000 Subject: [PATCH] Improved error message printed when ct2ctml fails Now we actually print the contents of the log file. --- src/base/ct2ctml.cpp | 48 +++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/src/base/ct2ctml.cpp b/src/base/ct2ctml.cpp index 8b179207b..a08bfefae 100644 --- a/src/base/ct2ctml.cpp +++ b/src/base/ct2ctml.cpp @@ -12,11 +12,11 @@ #include "cantera/base/stringUtils.h" #include +#include #include #include #include - // These defines are needed for the windows Sleep() function // - comment them out if you don't want the Sleep function. //#ifdef _WIN32 @@ -158,36 +158,24 @@ void ct2ctml(const char* file, const int debug) // This command works on windows machines if Windows.h and Winbase.h are included // Sleep(5000); #endif - // show the contents of the log file on the screen - try { - char ch=0; - string s = ""; - ifstream ferr("ct2ctml.log"); - if (ferr) { - while (!ferr.eof()) { - ferr.get(ch); - s += ch; - if (ch == '\n') { - writelog(s); - s = ""; - } - } - ferr.close(); - } else { - if (debug > 0) { - writelog("cannot open ct2ctml.log for reading.\n"); - } - } - } catch (std::exception& err) { - writelog("ct2ctml: Exception while trying to parse ct2ctml.log:\n"); - writelog(err.what()); - } + if (ierr != 0) { - string msg = cmd; - writelog("ct2ctml: throw cantera error \n"); - throw CanteraError("ct2ctml", - "could not convert input file to CTML.\n " - "Command line was: \n" + msg); + // Generate an error message that includes the contents of the + // ct2ctml log file. + stringstream message; + message << "Error converting input file \"" << file << "\" to CTML.\n"; + message << "Command was:\n\n"; + message << cmd << "\n\n"; + ifstream ferr(logfile.c_str()); + if (ferr) { + message << "-------------- start of ct2ctml.log --------------\n"; + message << ferr.rdbuf(); + message << "--------------- end of ct2ctml.log ---------------"; + } else { + message << "Additionally, the contents of ct2ctml.log" + "could not be read"; + } + throw CanteraError("ct2ctml", message.str()); } // if the conversion succeeded and DEBUG_PATHS is not defined,