From 28b866af43c533a59be9db7d061065698cb9e2c9 Mon Sep 17 00:00:00 2001 From: john30 Date: Fri, 27 Mar 2015 22:36:12 +0100 Subject: [PATCH] print error position if reading config fails --- src/ebusd/main.cpp | 4 ++-- src/lib/ebus/filereader.h | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index c6515a12..9fe8e00b 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -490,13 +490,13 @@ result_t loadConfigFiles(DataFieldTemplates* templates, MessageMap* messages, bo if (result == RESULT_OK) logInfo(lf_main, "read templates"); 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); if (result == RESULT_OK) logInfo(lf_main, "read config files"); 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)); diff --git a/src/lib/ebus/filereader.h b/src/lib/ebus/filereader.h index ea6366d4..7cf617b9 100644 --- a/src/lib/ebus/filereader.h +++ b/src/lib/ebus/filereader.h @@ -144,16 +144,26 @@ public: if (result != RESULT_OK) { if (!verbose) { ifs.close(); + ostringstream error; + error << filename <<":" << static_cast(lineNo); + m_lastError = error.str(); return result; } printErrorPos(row.begin(), end, it, filename, lineNo, result); - } + } else if (!verbose) + m_lastError = ""; } ifs.close(); 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. * @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). */ bool m_supportsDefaults; + /** a @a string describing the last error position. */ + string m_lastError; + }; #endif // LIBEBUS_FILEREADER_H_