From 38bb62c59a369ff80c8d30322bd1c6e18889cc05 Mon Sep 17 00:00:00 2001 From: benthompson15 Date: Tue, 13 Aug 2019 16:03:27 -0500 Subject: [PATCH] Add some exception handling. --- src/Replicator.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Replicator.cpp b/src/Replicator.cpp index 1237cd681..f91c9e74f 100644 --- a/src/Replicator.cpp +++ b/src/Replicator.cpp @@ -184,12 +184,43 @@ int Replicator::addJournalEntry(const boost::filesystem::path &filename, const u { // read the existing header and check if max_offset needs to be updated size_t tmp; - boost::shared_array headertxt = seekToEndOfHeader1(fd, &tmp); + boost::shared_array headertxt; + try + { + headertxt = seekToEndOfHeader1(fd, &tmp); + } + catch (std::runtime_error& e) + { + mpLogger->log(LOG_CRIT,"%s",e.what()); + errno = EIO; + return -1; + } + catch (...) + { + mpLogger->log(LOG_CRIT,"Unknown exception caught during seekToEndOfHeader1."); + errno = EIO; + return -1; + } stringstream ss; ss << headertxt.get(); headerRollback = headertxt.get(); - boost::property_tree::ptree header; - boost::property_tree::json_parser::read_json(ss, header); + boost::property_tree::ptree header; + try + { + boost::property_tree::json_parser::read_json(ss, header); + } + catch (const boost::property_tree::json_parser::json_parser_error& e) + { + mpLogger->log(LOG_CRIT,"%s",e.what()); + errno = EIO; + return -1; + } + catch (...) + { + mpLogger->log(LOG_CRIT,"Unknown exception caught during read_json."); + errno = EIO; + return -1; + } assert(header.get("version") == 1); uint64_t currentMaxOffset = header.get("max_offset"); if (thisEntryMaxOffset > currentMaxOffset)