Skip to content

Commit 6c19ca1

Browse files
committed
Merge pull request #3490
7e08e29 better std::exception logging for block/undo files (Philip Kaufmann)
2 parents 08ede8e + 7e08e29 commit 6c19ca1

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
@@ -883,11 +883,11 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
883883
fseek(file, postx.nTxOffset, SEEK_CUR);
884884
file >> txOut;
885885
} catch (std::exception &e) {
886-
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
886+
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
887887
}
888888
hashBlock = header.GetHash();
889889
if (txOut.GetHash() != hash)
890-
return error("%s() : txid mismatch", __PRETTY_FUNCTION__);
890+
return error("%s : txid mismatch", __PRETTY_FUNCTION__);
891891
return true;
892892
}
893893
}
@@ -936,7 +936,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
936936
// Open history file to append
937937
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
938938
if (!fileout)
939-
return error("WriteBlockToDisk() : OpenBlockFile failed");
939+
return error("WriteBlockToDisk : OpenBlockFile failed");
940940

941941
// Write index header
942942
unsigned int nSize = fileout.GetSerializeSize(block);
@@ -945,7 +945,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
945945
// Write block
946946
long fileOutPos = ftell(fileout);
947947
if (fileOutPos < 0)
948-
return error("WriteBlockToDisk() : ftell failed");
948+
return error("WriteBlockToDisk : ftell failed");
949949
pos.nPos = (unsigned int)fileOutPos;
950950
fileout << block;
951951

@@ -964,19 +964,19 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos)
964964
// Open history file to read
965965
CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
966966
if (!filein)
967-
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : OpenBlockFile failed");
967+
return error("ReadBlockFromDisk : OpenBlockFile failed");
968968

969969
// Read block
970970
try {
971971
filein >> block;
972972
}
973973
catch (std::exception &e) {
974-
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
974+
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
975975
}
976976

977977
// Check the header
978978
if (!CheckProofOfWork(block.GetHash(), block.nBits))
979-
return error("ReadBlockFromDisk(CBlock&, CDiskBlockPos&) : errors in block header");
979+
return error("ReadBlockFromDisk : Errors in block header");
980980

981981
return true;
982982
}
@@ -2876,7 +2876,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
28762876
break;
28772877
}
28782878
} catch (std::exception &e) {
2879-
LogPrintf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__);
2879+
LogPrintf("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
28802880
}
28812881
}
28822882
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)