Skip to content

Commit

Permalink
better std::exception logging for block/undo files
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Kaufmann committed Jan 6, 2014
1 parent 37d30ec commit 7e08e29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/main.cpp
Expand Up @@ -878,11 +878,11 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
fseek(file, postx.nTxOffset, SEEK_CUR);
file >> txOut;
} catch (std::exception &e) {
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}
hashBlock = header.GetHash();
if (txOut.GetHash() != hash)
return error("%s() : txid mismatch", __PRETTY_FUNCTION__);
return error("%s : txid mismatch", __PRETTY_FUNCTION__);
return true;
}
}
Expand Down Expand Up @@ -931,7 +931,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
// Open history file to append
CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
if (!fileout)
return error("WriteBlockToDisk() : OpenBlockFile failed");
return error("WriteBlockToDisk : OpenBlockFile failed");

// Write index header
unsigned int nSize = fileout.GetSerializeSize(block);
Expand All @@ -940,7 +940,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
// Write block
long fileOutPos = ftell(fileout);
if (fileOutPos < 0)
return error("WriteBlockToDisk() : ftell failed");
return error("WriteBlockToDisk : ftell failed");
pos.nPos = (unsigned int)fileOutPos;
fileout << block;

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

// Read block
try {
filein >> block;
}
catch (std::exception &e) {
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}

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

return true;
}
Expand Down Expand Up @@ -2852,7 +2852,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
break;
}
} catch (std::exception &e) {
LogPrintf("%s() : Deserialize or I/O error caught during load\n", __PRETTY_FUNCTION__);
LogPrintf("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}
}
fclose(fileIn);
Expand Down
10 changes: 5 additions & 5 deletions src/main.h
Expand Up @@ -336,7 +336,7 @@ class CBlockUndo
// Open history file to append
CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
if (!fileout)
return error("CBlockUndo::WriteToDisk() : OpenUndoFile failed");
return error("CBlockUndo::WriteToDisk : OpenUndoFile failed");

// Write index header
unsigned int nSize = fileout.GetSerializeSize(*this);
Expand All @@ -345,7 +345,7 @@ class CBlockUndo
// Write undo data
long fileOutPos = ftell(fileout);
if (fileOutPos < 0)
return error("CBlockUndo::WriteToDisk() : ftell failed");
return error("CBlockUndo::WriteToDisk : ftell failed");
pos.nPos = (unsigned int)fileOutPos;
fileout << *this;

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

// Read block
uint256 hashChecksum;
Expand All @@ -377,15 +377,15 @@ class CBlockUndo
filein >> hashChecksum;
}
catch (std::exception &e) {
return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
return error("%s : Deserialize or I/O error - %s", __PRETTY_FUNCTION__, e.what());
}

// Verify checksum
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
hasher << hashBlock;
hasher << *this;
if (hashChecksum != hasher.GetHash())
return error("CBlockUndo::ReadFromDisk() : checksum mismatch");
return error("CBlockUndo::ReadFromDisk : Checksum mismatch");

return true;
}
Expand Down

0 comments on commit 7e08e29

Please sign in to comment.