Skip to content

Commit fad0335

Browse files
author
MarcoFalke
committed
scripted-diff: Replace error() with LogError()
This fixes the log output when -logsourcelocations is used. Also, instead of 'ERROR:', the log will now say '[error]', like other errors logged with LogError. -BEGIN VERIFY SCRIPT- sed -i --regexp-extended 's! error\("([^"]+)"! LogError("\1\\n"!g' $( git grep -l ' error(' ./src/ ) -END VERIFY SCRIPT-
1 parent fa808fb commit fad0335

File tree

13 files changed

+97
-97
lines changed

13 files changed

+97
-97
lines changed

src/addrdb.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool SerializeDB(Stream& stream, const Data& data)
4444
hashwriter << Params().MessageStart() << data;
4545
stream << hashwriter.GetHash();
4646
} catch (const std::exception& e) {
47-
error("%s: Serialize or I/O error - %s", __func__, e.what());
47+
LogError("%s: Serialize or I/O error - %s\n", __func__, e.what());
4848
return false;
4949
}
5050

@@ -65,7 +65,7 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
6565
if (fileout.IsNull()) {
6666
fileout.fclose();
6767
remove(pathTmp);
68-
error("%s: Failed to open file %s", __func__, fs::PathToString(pathTmp));
68+
LogError("%s: Failed to open file %s\n", __func__, fs::PathToString(pathTmp));
6969
return false;
7070
}
7171

@@ -78,15 +78,15 @@ bool SerializeFileDB(const std::string& prefix, const fs::path& path, const Data
7878
if (!FileCommit(fileout.Get())) {
7979
fileout.fclose();
8080
remove(pathTmp);
81-
error("%s: Failed to flush file %s", __func__, fs::PathToString(pathTmp));
81+
LogError("%s: Failed to flush file %s\n", __func__, fs::PathToString(pathTmp));
8282
return false;
8383
}
8484
fileout.fclose();
8585

8686
// replace existing file, if any, with new file
8787
if (!RenameOver(pathTmp, path)) {
8888
remove(pathTmp);
89-
error("%s: Rename-into-place failed", __func__);
89+
LogError("%s: Rename-into-place failed\n", __func__);
9090
return false;
9191
}
9292

@@ -144,7 +144,7 @@ bool CBanDB::Write(const banmap_t& banSet)
144144
}
145145

146146
for (const auto& err : errors) {
147-
error("%s", err);
147+
LogError("%s\n", err);
148148
}
149149
return false;
150150
}

src/flatfile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize)
8282
{
8383
FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
8484
if (!file) {
85-
error("%s: failed to open file %d", __func__, pos.nFile);
85+
LogError("%s: failed to open file %d\n", __func__, pos.nFile);
8686
return false;
8787
}
8888
if (finalize && !TruncateFile(file, pos.nPos)) {
8989
fclose(file);
90-
error("%s: failed to truncate file %d", __func__, pos.nFile);
90+
LogError("%s: failed to truncate file %d\n", __func__, pos.nFile);
9191
return false;
9292
}
9393
if (!FileCommit(file)) {
9494
fclose(file);
95-
error("%s: failed to commit file %d", __func__, pos.nFile);
95+
LogError("%s: failed to commit file %d\n", __func__, pos.nFile);
9696
return false;
9797
}
9898
DirectoryCommit(m_dir);

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool BaseIndex::Commit()
229229
}
230230
}
231231
if (!ok) {
232-
error("%s: Failed to commit latest %s state", __func__, GetName());
232+
LogError("%s: Failed to commit latest %s state\n", __func__, GetName());
233233
return false;
234234
}
235235
return true;

src/index/blockfilterindex.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool BlockFilterIndex::CustomInit(const std::optional<interfaces::BlockKey>& blo
119119
// indicate database corruption or a disk failure, and starting the index would cause
120120
// further corruption.
121121
if (m_db->Exists(DB_FILTER_POS)) {
122-
error("%s: Cannot read current %s state; index may be corrupted",
122+
LogError("%s: Cannot read current %s state; index may be corrupted\n",
123123
__func__, GetName());
124124
return false;
125125
}
@@ -138,11 +138,11 @@ bool BlockFilterIndex::CustomCommit(CDBBatch& batch)
138138
// Flush current filter file to disk.
139139
AutoFile file{m_filter_fileseq->Open(pos)};
140140
if (file.IsNull()) {
141-
error("%s: Failed to open filter file %d", __func__, pos.nFile);
141+
LogError("%s: Failed to open filter file %d\n", __func__, pos.nFile);
142142
return false;
143143
}
144144
if (!FileCommit(file.Get())) {
145-
error("%s: Failed to commit filter file %d", __func__, pos.nFile);
145+
LogError("%s: Failed to commit filter file %d\n", __func__, pos.nFile);
146146
return false;
147147
}
148148

@@ -163,13 +163,13 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, const uint256&
163163
try {
164164
filein >> block_hash >> encoded_filter;
165165
if (Hash(encoded_filter) != hash) {
166-
error("Checksum mismatch in filter decode.");
166+
LogError("Checksum mismatch in filter decode.\n");
167167
return false;
168168
}
169169
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter), /*skip_decode_check=*/true);
170170
}
171171
catch (const std::exception& e) {
172-
error("%s: Failed to deserialize block filter from disk: %s", __func__, e.what());
172+
LogError("%s: Failed to deserialize block filter from disk: %s\n", __func__, e.what());
173173
return false;
174174
}
175175

@@ -242,7 +242,7 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
242242

243243
uint256 expected_block_hash = *Assert(block.prev_hash);
244244
if (read_out.first != expected_block_hash) {
245-
error("%s: previous block header belongs to unexpected block %s; expected %s",
245+
LogError("%s: previous block header belongs to unexpected block %s; expected %s\n",
246246
__func__, read_out.first.ToString(), expected_block_hash.ToString());
247247
return false;
248248
}
@@ -278,14 +278,14 @@ bool BlockFilterIndex::CustomAppend(const interfaces::BlockInfo& block)
278278

279279
for (int height = start_height; height <= stop_height; ++height) {
280280
if (!db_it.GetKey(key) || key.height != height) {
281-
error("%s: unexpected key in %s: expected (%c, %d)",
281+
LogError("%s: unexpected key in %s: expected (%c, %d)\n",
282282
__func__, index_name, DB_BLOCK_HEIGHT, height);
283283
return false;
284284
}
285285

286286
std::pair<uint256, DBVal> value;
287287
if (!db_it.GetValue(value)) {
288-
error("%s: unable to read value in %s at key (%c, %d)",
288+
LogError("%s: unable to read value in %s at key (%c, %d)\n",
289289
__func__, index_name, DB_BLOCK_HEIGHT, height);
290290
return false;
291291
}
@@ -340,11 +340,11 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
340340
const CBlockIndex* stop_index, std::vector<DBVal>& results)
341341
{
342342
if (start_height < 0) {
343-
error("%s: start height (%d) is negative", __func__, start_height);
343+
LogError("%s: start height (%d) is negative\n", __func__, start_height);
344344
return false;
345345
}
346346
if (start_height > stop_index->nHeight) {
347-
error("%s: start height (%d) is greater than stop height (%d)",
347+
LogError("%s: start height (%d) is greater than stop height (%d)\n",
348348
__func__, start_height, stop_index->nHeight);
349349
return false;
350350
}
@@ -362,7 +362,7 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
362362

363363
size_t i = static_cast<size_t>(height - start_height);
364364
if (!db_it->GetValue(values[i])) {
365-
error("%s: unable to read value in %s at key (%c, %d)",
365+
LogError("%s: unable to read value in %s at key (%c, %d)\n",
366366
__func__, index_name, DB_BLOCK_HEIGHT, height);
367367
return false;
368368
}
@@ -386,7 +386,7 @@ static bool LookupRange(CDBWrapper& db, const std::string& index_name, int start
386386
}
387387

388388
if (!db.Read(DBHashKey(block_hash), results[i])) {
389-
error("%s: unable to read value in %s at key (%c, %s)",
389+
LogError("%s: unable to read value in %s at key (%c, %s)\n",
390390
__func__, index_name, DB_BLOCK_HASH, block_hash.ToString());
391391
return false;
392392
}

src/index/coinstatsindex.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
138138
read_out.first.ToString(), expected_block_hash.ToString());
139139

140140
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
141-
error("%s: previous block header not found; expected %s",
141+
LogError("%s: previous block header not found; expected %s\n",
142142
__func__, expected_block_hash.ToString());
143143
return false;
144144
}
@@ -246,14 +246,14 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
246246

247247
for (int height = start_height; height <= stop_height; ++height) {
248248
if (!db_it.GetKey(key) || key.height != height) {
249-
error("%s: unexpected key in %s: expected (%c, %d)",
249+
LogError("%s: unexpected key in %s: expected (%c, %d)\n",
250250
__func__, index_name, DB_BLOCK_HEIGHT, height);
251251
return false;
252252
}
253253

254254
std::pair<uint256, DBVal> value;
255255
if (!db_it.GetValue(value)) {
256-
error("%s: unable to read value in %s at key (%c, %d)",
256+
LogError("%s: unable to read value in %s at key (%c, %d)\n",
257257
__func__, index_name, DB_BLOCK_HEIGHT, height);
258258
return false;
259259
}
@@ -288,7 +288,7 @@ bool CoinStatsIndex::CustomRewind(const interfaces::BlockKey& current_tip, const
288288
CBlock block;
289289

290290
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *iter_tip)) {
291-
error("%s: Failed to read block %s from disk",
291+
LogError("%s: Failed to read block %s from disk\n",
292292
__func__, iter_tip->GetBlockHash().ToString());
293293
return false;
294294
}
@@ -357,7 +357,7 @@ bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block
357357
// exist. Any other errors indicate database corruption or a disk
358358
// failure, and starting the index would cause further corruption.
359359
if (m_db->Exists(DB_MUHASH)) {
360-
error("%s: Cannot read current %s state; index may be corrupted",
360+
LogError("%s: Cannot read current %s state; index may be corrupted\n",
361361
__func__, GetName());
362362
return false;
363363
}
@@ -366,15 +366,15 @@ bool CoinStatsIndex::CustomInit(const std::optional<interfaces::BlockKey>& block
366366
if (block) {
367367
DBVal entry;
368368
if (!LookUpOne(*m_db, *block, entry)) {
369-
error("%s: Cannot read current %s state; index may be corrupted",
369+
LogError("%s: Cannot read current %s state; index may be corrupted\n",
370370
__func__, GetName());
371371
return false;
372372
}
373373

374374
uint256 out;
375375
m_muhash.Finalize(out);
376376
if (entry.muhash != out) {
377-
error("%s: Cannot read current %s state; index may be corrupted",
377+
LogError("%s: Cannot read current %s state; index may be corrupted\n",
378378
__func__, GetName());
379379
return false;
380380
}
@@ -429,7 +429,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
429429
read_out.first.ToString(), expected_block_hash.ToString());
430430

431431
if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
432-
error("%s: previous block header not found; expected %s",
432+
LogError("%s: previous block header not found; expected %s\n",
433433
__func__, expected_block_hash.ToString());
434434
return false;
435435
}

src/index/txindex.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ bool TxIndex::FindTx(const uint256& tx_hash, uint256& block_hash, CTransactionRe
8181

8282
AutoFile file{m_chainstate->m_blockman.OpenBlockFile(postx, true)};
8383
if (file.IsNull()) {
84-
error("%s: OpenBlockFile failed", __func__);
84+
LogError("%s: OpenBlockFile failed\n", __func__);
8585
return false;
8686
}
8787
CBlockHeader header;
8888
try {
8989
file >> header;
9090
if (fseek(file.Get(), postx.nTxOffset, SEEK_CUR)) {
91-
error("%s: fseek(...) failed", __func__);
91+
LogError("%s: fseek(...) failed\n", __func__);
9292
return false;
9393
}
9494
file >> TX_WITH_WITNESS(tx);
9595
} catch (const std::exception& e) {
96-
error("%s: Deserialize or I/O error - %s", __func__, e.what());
96+
LogError("%s: Deserialize or I/O error - %s\n", __func__, e.what());
9797
return false;
9898
}
9999
if (tx->GetHash() != tx_hash) {
100-
error("%s: txid mismatch", __func__);
100+
LogError("%s: txid mismatch\n", __func__);
101101
return false;
102102
}
103103
block_hash = header.GetHash();

src/kernel/coinstats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static bool ComputeUTXOStats(CCoinsView* view, CCoinsStats& stats, T hash_obj, c
134134
outputs[key.n] = std::move(coin);
135135
stats.coins_count++;
136136
} else {
137-
error("%s: unable to read value", __func__);
137+
LogError("%s: unable to read value\n", __func__);
138138
return false;
139139
}
140140
pcursor->Next();

src/net.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ void CNode::SetAddrLocal(const CService& addrLocalIn) {
575575
AssertLockNotHeld(m_addr_local_mutex);
576576
LOCK(m_addr_local_mutex);
577577
if (addrLocal.IsValid()) {
578-
error("Addr local already set for node: %i. Refusing to change from %s to %s", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort());
578+
LogError("Addr local already set for node: %i. Refusing to change from %s to %s\n", id, addrLocal.ToStringAddrPort(), addrLocalIn.ToStringAddrPort());
579579
} else {
580580
addrLocal = addrLocalIn;
581581
}

src/netbase.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
338338
IntrRecvError recvr;
339339
LogPrint(BCLog::NET, "SOCKS5 connecting %s\n", strDest);
340340
if (strDest.size() > 255) {
341-
error("Hostname too long");
341+
LogError("Hostname too long\n");
342342
return false;
343343
}
344344
// Construct the version identifier/method selection message
@@ -359,15 +359,15 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
359359
return false;
360360
}
361361
if (pchRet1[0] != SOCKSVersion::SOCKS5) {
362-
error("Proxy failed to initialize");
362+
LogError("Proxy failed to initialize\n");
363363
return false;
364364
}
365365
if (pchRet1[1] == SOCKS5Method::USER_PASS && auth) {
366366
// Perform username/password authentication (as described in RFC1929)
367367
std::vector<uint8_t> vAuth;
368368
vAuth.push_back(0x01); // Current (and only) version of user/pass subnegotiation
369369
if (auth->username.size() > 255 || auth->password.size() > 255) {
370-
error("Proxy username or password too long");
370+
LogError("Proxy username or password too long\n");
371371
return false;
372372
}
373373
vAuth.push_back(auth->username.size());
@@ -378,17 +378,17 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
378378
LogPrint(BCLog::PROXY, "SOCKS5 sending proxy authentication %s:%s\n", auth->username, auth->password);
379379
uint8_t pchRetA[2];
380380
if (InterruptibleRecv(pchRetA, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
381-
error("Error reading proxy authentication response");
381+
LogError("Error reading proxy authentication response\n");
382382
return false;
383383
}
384384
if (pchRetA[0] != 0x01 || pchRetA[1] != 0x00) {
385-
error("Proxy authentication unsuccessful");
385+
LogError("Proxy authentication unsuccessful\n");
386386
return false;
387387
}
388388
} else if (pchRet1[1] == SOCKS5Method::NOAUTH) {
389389
// Perform no authentication
390390
} else {
391-
error("Proxy requested wrong authentication method %02x", pchRet1[1]);
391+
LogError("Proxy requested wrong authentication method %02x\n", pchRet1[1]);
392392
return false;
393393
}
394394
std::vector<uint8_t> vSocks5;
@@ -409,12 +409,12 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
409409
* error message. */
410410
return false;
411411
} else {
412-
error("Error while reading proxy response");
412+
LogError("Error while reading proxy response\n");
413413
return false;
414414
}
415415
}
416416
if (pchRet2[0] != SOCKSVersion::SOCKS5) {
417-
error("Proxy failed to accept request");
417+
LogError("Proxy failed to accept request\n");
418418
return false;
419419
}
420420
if (pchRet2[1] != SOCKS5Reply::SUCCEEDED) {
@@ -423,7 +423,7 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
423423
return false;
424424
}
425425
if (pchRet2[2] != 0x00) { // Reserved field must be 0
426-
error("Error: malformed proxy response");
426+
LogError("Error: malformed proxy response\n");
427427
return false;
428428
}
429429
uint8_t pchRet3[256];
@@ -433,30 +433,30 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
433433
case SOCKS5Atyp::DOMAINNAME: {
434434
recvr = InterruptibleRecv(pchRet3, 1, g_socks5_recv_timeout, sock);
435435
if (recvr != IntrRecvError::OK) {
436-
error("Error reading from proxy");
436+
LogError("Error reading from proxy\n");
437437
return false;
438438
}
439439
int nRecv = pchRet3[0];
440440
recvr = InterruptibleRecv(pchRet3, nRecv, g_socks5_recv_timeout, sock);
441441
break;
442442
}
443443
default: {
444-
error("Error: malformed proxy response");
444+
LogError("Error: malformed proxy response\n");
445445
return false;
446446
}
447447
}
448448
if (recvr != IntrRecvError::OK) {
449-
error("Error reading from proxy");
449+
LogError("Error reading from proxy\n");
450450
return false;
451451
}
452452
if (InterruptibleRecv(pchRet3, 2, g_socks5_recv_timeout, sock) != IntrRecvError::OK) {
453-
error("Error reading from proxy");
453+
LogError("Error reading from proxy\n");
454454
return false;
455455
}
456456
LogPrint(BCLog::NET, "SOCKS5 connected %s\n", strDest);
457457
return true;
458458
} catch (const std::runtime_error& e) {
459-
error("Error during SOCKS5 proxy handshake: %s", e.what());
459+
LogError("Error during SOCKS5 proxy handshake: %s\n", e.what());
460460
return false;
461461
}
462462
}

0 commit comments

Comments
 (0)