print error position if reading config fails

This commit is contained in:
john30
2015-03-27 22:36:12 +01:00
parent 5bd74035c5
commit 28b866af43
2 changed files with 16 additions and 3 deletions
+2 -2
View File
@@ -490,13 +490,13 @@ result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bo
if (result == RESULT_OK) if (result == RESULT_OK)
logInfo(lf_main, "read templates"); logInfo(lf_main, "read templates");
else else
logError(lf_main, "error reading templates: %s", getResultCode(result)); logError(lf_main, "error reading templates: %s, %s", getResultCode(result), templates->getLastError().c_str());
result = readConfigFiles(path, ".csv", templates, messages, verbose); result = readConfigFiles(path, ".csv", templates, messages, verbose);
if (result == RESULT_OK) if (result == RESULT_OK)
logInfo(lf_main, "read config files"); logInfo(lf_main, "read config files");
else else
logError(lf_main, "error reading config files: %s", getResultCode(result)); logError(lf_main, "error reading config files: %s, %s", getResultCode(result), messages->getLastError().c_str());
logNotice(lf_main, "found messages: %d (%d poll, %d update)", messages->size(), messages->sizePoll(), messages->size(true)); logNotice(lf_main, "found messages: %d (%d poll, %d update)", messages->size(), messages->sizePoll(), messages->size(true));
+14 -1
View File
@@ -144,16 +144,26 @@ public:
if (result != RESULT_OK) { if (result != RESULT_OK) {
if (!verbose) { if (!verbose) {
ifs.close(); ifs.close();
ostringstream error;
error << filename <<":" << static_cast<unsigned>(lineNo);
m_lastError = error.str();
return result; return result;
} }
printErrorPos(row.begin(), end, it, filename, lineNo, result); printErrorPos(row.begin(), end, it, filename, lineNo, result);
} } else if (!verbose)
m_lastError = "";
} }
ifs.close(); ifs.close();
return RESULT_OK; return RESULT_OK;
} }
/**
* Return a @a string describing the last error position.
* @return a @a string describing the last error position.
*/
virtual string getLastError() { return m_lastError; }
/** /**
* Add a definition that was read from a file. * Add a definition that was read from a file.
* @param begin an iterator to the first column of the definition row to read. * @param begin an iterator to the first column of the definition row to read.
@@ -171,6 +181,9 @@ private:
/** whether this instance supports rows with defaults (starting with a star). */ /** whether this instance supports rows with defaults (starting with a star). */
bool m_supportsDefaults; bool m_supportsDefaults;
/** a @a string describing the last error position. */
string m_lastError;
}; };
#endif // LIBEBUS_FILEREADER_H_ #endif // LIBEBUS_FILEREADER_H_