Skip to content

Commit 9eb1e1e

Browse files
committed
Merge pull request #3602
2fdd4c7 better std::exception logging for CAddrDb (Philip Kaufmann)
2 parents 51cb8fe + 2fdd4c7 commit 9eb1e1e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/net.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,21 +1944,21 @@ bool CAddrDB::Write(const CAddrMan& addr)
19441944
FILE *file = fopen(pathTmp.string().c_str(), "wb");
19451945
CAutoFile fileout = CAutoFile(file, SER_DISK, CLIENT_VERSION);
19461946
if (!fileout)
1947-
return error("CAddrman::Write() : open failed");
1947+
return error("%s : Failed to open file %s", __func__, pathTmp.string());
19481948

19491949
// Write and commit header, data
19501950
try {
19511951
fileout << ssPeers;
19521952
}
19531953
catch (std::exception &e) {
1954-
return error("CAddrman::Write() : I/O error");
1954+
return error("%s : Serialize or I/O error - %s", __func__, e.what());
19551955
}
19561956
FileCommit(fileout);
19571957
fileout.fclose();
19581958

19591959
// replace existing peers.dat, if any, with new peers.dat.XXXX
19601960
if (!RenameOver(pathTmp, pathAddr))
1961-
return error("CAddrman::Write() : Rename-into-place failed");
1961+
return error("%s : Rename-into-place failed", __func__);
19621962

19631963
return true;
19641964
}
@@ -1969,13 +1969,14 @@ bool CAddrDB::Read(CAddrMan& addr)
19691969
FILE *file = fopen(pathAddr.string().c_str(), "rb");
19701970
CAutoFile filein = CAutoFile(file, SER_DISK, CLIENT_VERSION);
19711971
if (!filein)
1972-
return error("CAddrman::Read() : open failed");
1972+
return error("%s : Failed to open file %s", __func__, pathAddr.string());
19731973

19741974
// use file size to size memory buffer
19751975
int fileSize = boost::filesystem::file_size(pathAddr);
19761976
int dataSize = fileSize - sizeof(uint256);
19771977
// Don't try to resize to a negative number if file is small
1978-
if ( dataSize < 0 ) dataSize = 0;
1978+
if (dataSize < 0)
1979+
dataSize = 0;
19791980
vector<unsigned char> vchData;
19801981
vchData.resize(dataSize);
19811982
uint256 hashIn;
@@ -1986,7 +1987,7 @@ bool CAddrDB::Read(CAddrMan& addr)
19861987
filein >> hashIn;
19871988
}
19881989
catch (std::exception &e) {
1989-
return error("CAddrman::Read() 2 : I/O error or stream data corrupted");
1990+
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
19901991
}
19911992
filein.fclose();
19921993

@@ -1995,7 +1996,7 @@ bool CAddrDB::Read(CAddrMan& addr)
19951996
// verify stored checksum matches input data
19961997
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
19971998
if (hashIn != hashTmp)
1998-
return error("CAddrman::Read() : checksum mismatch; data corrupted");
1999+
return error("%s : Checksum mismatch, data corrupted", __func__);
19992000

20002001
unsigned char pchMsgTmp[4];
20012002
try {
@@ -2004,13 +2005,13 @@ bool CAddrDB::Read(CAddrMan& addr)
20042005

20052006
// ... verify the network matches ours
20062007
if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp)))
2007-
return error("CAddrman::Read() : invalid network magic number");
2008+
return error("%s : Invalid network magic number", __func__);
20082009

20092010
// de-serialize address data into one CAddrMan object
20102011
ssPeers >> addr;
20112012
}
20122013
catch (std::exception &e) {
2013-
return error("CAddrman::Read() : I/O error or stream data corrupted");
2014+
return error("%s : Deserialize or I/O error - %s", __func__, e.what());
20142015
}
20152016

20162017
return true;

0 commit comments

Comments
 (0)