Skip to content

Commit 869cf12

Browse files
committed
dbwrapper: Move HandleError to dbwrapper_private
HandleError is implementation-specific.
1 parent b69836d commit 869cf12

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/dbwrapper.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@
1515
#include <memenv.h>
1616
#include <stdint.h>
1717

18-
void HandleError(const leveldb::Status& status)
19-
{
20-
if (status.ok())
21-
return;
22-
LogPrintf("%s\n", status.ToString());
23-
if (status.IsCorruption())
24-
throw dbwrapper_error("Database corrupted");
25-
if (status.IsIOError())
26-
throw dbwrapper_error("Database I/O error");
27-
if (status.IsNotFound())
28-
throw dbwrapper_error("Database entry missing");
29-
throw dbwrapper_error("Unknown database error");
30-
}
31-
3218
static leveldb::Options GetOptions(size_t nCacheSize)
3319
{
3420
leveldb::Options options;
@@ -61,13 +47,13 @@ CDBWrapper::CDBWrapper(const boost::filesystem::path& path, size_t nCacheSize, b
6147
if (fWipe) {
6248
LogPrintf("Wiping LevelDB in %s\n", path.string());
6349
leveldb::Status result = leveldb::DestroyDB(path.string(), options);
64-
HandleError(result);
50+
dbwrapper_private::HandleError(result);
6551
}
6652
TryCreateDirectory(path);
6753
LogPrintf("Opening LevelDB in %s\n", path.string());
6854
}
6955
leveldb::Status status = leveldb::DB::Open(options, path.string(), &pdb);
70-
HandleError(status);
56+
dbwrapper_private::HandleError(status);
7157
LogPrintf("Opened LevelDB successfully\n");
7258

7359
// The base-case obfuscation key, which is a noop.
@@ -105,7 +91,7 @@ CDBWrapper::~CDBWrapper()
10591
bool CDBWrapper::WriteBatch(CDBBatch& batch, bool fSync)
10692
{
10793
leveldb::Status status = pdb->Write(fSync ? syncoptions : writeoptions, &batch.batch);
108-
HandleError(status);
94+
dbwrapper_private::HandleError(status);
10995
return true;
11096
}
11197

@@ -143,6 +129,20 @@ void CDBIterator::Next() { piter->Next(); }
143129

144130
namespace dbwrapper_private {
145131

132+
void HandleError(const leveldb::Status& status)
133+
{
134+
if (status.ok())
135+
return;
136+
LogPrintf("%s\n", status.ToString());
137+
if (status.IsCorruption())
138+
throw dbwrapper_error("Database corrupted");
139+
if (status.IsIOError())
140+
throw dbwrapper_error("Database I/O error");
141+
if (status.IsNotFound())
142+
throw dbwrapper_error("Database entry missing");
143+
throw dbwrapper_error("Unknown database error");
144+
}
145+
146146
const std::vector<unsigned char>& GetObfuscateKey(const CDBWrapper &w)
147147
{
148148
return w.obfuscate_key;

src/dbwrapper.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ class dbwrapper_error : public std::runtime_error
2323
dbwrapper_error(const std::string& msg) : std::runtime_error(msg) {}
2424
};
2525

26-
void HandleError(const leveldb::Status& status);
27-
2826
class CDBWrapper;
2927

3028
/** These should be considered an implementation detail of the specific database.
3129
*/
3230
namespace dbwrapper_private {
3331

32+
/** Handle database error by throwing dbwrapper_error exception.
33+
*/
34+
void HandleError(const leveldb::Status& status);
35+
3436
/** Work around circular dependency, as well as for testing in dbwrapper_tests.
3537
* Database obfuscation should be considered an implementation detail of the
3638
* specific database.
@@ -208,7 +210,7 @@ class CDBWrapper
208210
if (status.IsNotFound())
209211
return false;
210212
LogPrintf("LevelDB read failure: %s\n", status.ToString());
211-
HandleError(status);
213+
dbwrapper_private::HandleError(status);
212214
}
213215
try {
214216
CDataStream ssValue(strValue.data(), strValue.data() + strValue.size(), SER_DISK, CLIENT_VERSION);
@@ -242,7 +244,7 @@ class CDBWrapper
242244
if (status.IsNotFound())
243245
return false;
244246
LogPrintf("LevelDB read failure: %s\n", status.ToString());
245-
HandleError(status);
247+
dbwrapper_private::HandleError(status);
246248
}
247249
return true;
248250
}

0 commit comments

Comments
 (0)