Skip to content

Commit 7e08e29

Browse files
author
Philip Kaufmann
committed
better std::exception logging for block/undo files
1 parent 37d30ec commit 7e08e29

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,11 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
878878
fseek(file, postx.nTxOffset, SEEK_CUR);
879879
file >> txOut;
880880
} catch (std::exception &e) {
881-
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
881+
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
882882
}
883883
hashBlock = header.GetHash();
884884
if (txOut.GetHash() != hash)
885-
return error("%s() : txid mismatch", __PRETTY_FUNCTION__);
885+
return error("%s : txid mismatch", __PRETTY_FUNCTION__);
886886
return true;
887887
}
888888
}
@@ -931,7 +931,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
931931
// Open history file to append
932932
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
933933
if (!fileout)
934-
return error("WriteBlockToDisk() : OpenBlockFile failed");
934+
return error("WriteBlockToDisk : OpenBlockFile failed");
935935

936936
// Write index header
937937
unsigned int nSize = fileout.GetSerializeSize(block);
@@ -940,7 +940,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
940940
// Write block
941941
long fileOutPos = ftell(fileout);
942942
if (fileOutPos < 0)
943-
return error("WriteBlockToDisk() : ftell failed");
943+
return error("WriteBlockToDisk : ftell failed");
944944
pos.nPos = (unsigned int)fileOutPos;
945945
fileout << block;
946946

@@ -959,19 +959,19 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
959959
// Open history file to read
960960
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
961961
if (!filein)
962-
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : OpenBlockFile failed");
962+
return error("ReadBlockFromDisk : OpenBlockFile failed");
963963

964964
// Read block
965965
try {
966966
filein >> block;
967967
}
968968
catch (std::exception &e) {
969-
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
969+
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
970970
}
971971

972972
// Check the header
973973
if (!CheckProofOfWork(block.GetHash(), block.nBits))
974-
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : errors in block header");
974+
return error("ReadBlockFromDisk : Errors in block header");
975975

976976
return true;
977977
}
@@ -2852,7 +2852,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
28522852
break;
28532853
}
28542854
} catch (std::exception &e) {
2855-
LogPrintf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__);
2855+
LogPrintf("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
28562856
}
28572857
}
28582858
fclose(fileIn);

src/main.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class CBlockUndo
336336
// Open history file to append
337337
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
338338
if (!fileout)
339-
return error("CBlockUndo::WriteToDisk() : OpenUndoFile failed");
339+
return error("CBlockUndo::WriteToDisk : OpenUndoFile failed");
340340

341341
// Write index header
342342
unsigned int nSize = fileout.GetSerializeSize(*this);
@@ -345,7 +345,7 @@ class CBlockUndo
345345
// Write undo data
346346
long fileOutPos = ftell(fileout);
347347
if (fileOutPos < 0)
348-
return error("CBlockUndo::WriteToDisk() : ftell failed");
348+
return error("CBlockUndo::WriteToDisk : ftell failed");
349349
pos.nPos = (unsigned int)fileOutPos;
350350
fileout << *this;
351351

@@ -368,7 +368,7 @@ class CBlockUndo
368368
// Open history file to read
369369
CAutoFile filein = CAutoFile(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
370370
if (!filein)
371-
return error("CBlockUndo::ReadFromDisk() : OpenBlockFile failed");
371+
return error("CBlockUndo::ReadFromDisk : OpenBlockFile failed");
372372

373373
// Read block
374374
uint256 hashChecksum;
@@ -377,15 +377,15 @@ class CBlockUndo
377377
filein >> hashChecksum;
378378
}
379379
catch (std::exception &e) {
380-
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
380+
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
381381
}
382382

383383
// Verify checksum
384384
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
385385
hasher << hashBlock;
386386
hasher << *this;
387387
if (hashChecksum != hasher.GetHash())
388-
return error("CBlockUndo::ReadFromDisk() : checksum mismatch");
388+
return error("CBlockUndo::ReadFromDisk : Checksum mismatch");
389389

390390
return true;
391391
}

0 commit comments

Comments
 (0)