From a6dea8846d07760dd96cf89c960f07d5684f6178 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Thu, 30 Jan 2014 10:50:52 +0100 Subject: [PATCH] Better std exception logging for CAddrDb --- src/net.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index 01815ff5c..c428d4649 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1942,21 +1942,21 @@ bool CAddrDB::Write(const CAddrMan& addr) FILE *file = fopen(pathTmp.string().c_str(), "wb"); CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION); if (!fileout) - return error("CAddrman::Write() : open failed"); + return error("%s : Failed to open file %s", __func__, pathTmp.string()); // Write and commit header, data try { fileout << ssPeers; } catch (std::exception &e) { - return error("CAddrman::Write() : I/O error"); + return error("%s : Serialize or I/O error - %s", __func__, e.what()); } FileCommit(fileout); fileout.fclose(); // replace existing peers.dat, if any, with new peers.dat.XXXX if (!RenameOver(pathTmp, pathAddr)) - return error("CAddrman::Write() : Rename-into-place failed"); + return error("%s : Rename-into-place failed", __func__); return true; } @@ -1967,13 +1967,14 @@ bool CAddrDB::Read(CAddrMan& addr) FILE *file = fopen(pathAddr.string().c_str(), "rb"); CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION); if (!filein) - return error("CAddrman::Read() : open failed"); + return error("%s : Failed to open file %s", __func__, pathAddr.string()); // use file size to size memory buffer - int fileSize = GetFilesize(filein); + int fileSize = boost::filesystem::file_size(pathAddr); int dataSize = fileSize - sizeof(uint256); - //Don't try to resize to a negative number if file is small - if ( dataSize < 0 ) dataSize = 0; + // Don't try to resize to a negative number if file is small + if (dataSize < 0) + dataSize = 0; vector vchData; vchData.resize(dataSize); uint256 hashIn; @@ -1984,7 +1985,7 @@ bool CAddrDB::Read(CAddrMan& addr) filein >> hashIn; } catch (std::exception &e) { - return error("CAddrman::Read() 2 : I/O error or stream data corrupted"); + return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } filein.fclose(); @@ -1993,7 +1994,7 @@ bool CAddrDB::Read(CAddrMan& addr) // verify stored checksum matches input data uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end()); if (hashIn != hashTmp) - return error("CAddrman::Read() : checksum mismatch; data corrupted"); + return error("%s : Checksum mismatch, data corrupted", __func__); unsigned char pchMsgTmp[4]; try { @@ -2002,13 +2003,13 @@ bool CAddrDB::Read(CAddrMan& addr) // ... verify the network matches ours if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) - return error("CAddrman::Read() : invalid network magic number"); + return error("%s : Invalid network magic number", __func__); // de-serialize address data into one CAddrMan object ssPeers >> addr; } catch (std::exception &e) { - return error("CAddrman::Read() : I/O error or stream data corrupted"); + return error("%s : Deserialize or I/O error - %s", __func__, e.what()); } return true;