Better error message.

GitOrigin-RevId: 099dc02976ede7814d0296d37c63c260652e7a8a
This commit is contained in:
levlam 2018-04-02 23:11:45 +03:00
parent ca5d9a5ceb
commit ac8b30f6e6
3 changed files with 7 additions and 3 deletions

View File

@ -21,7 +21,11 @@ class SqliteConnectionSafe {
SqliteConnectionSafe() = default;
explicit SqliteConnectionSafe(string name, DbKey key = DbKey::empty())
: lsls_connection_([name = name, key = std::move(key)] {
auto db = SqliteDb::open_with_key(name, key).move_as_ok();
auto r_db = SqliteDb::open_with_key(name, key);
if (r_db.is_error()) {
LOG(FATAL) << "Can't open database " << name << ": " << r_db.error();
}
auto db = r_db.move_as_ok();
db.exec("PRAGMA synchronous=NORMAL").ensure();
db.exec("PRAGMA temp_store=MEMORY").ensure();
db.exec("PRAGMA secure_delete=1").ensure();

View File

@ -156,7 +156,7 @@ Result<SqliteDb> SqliteDb::open_with_key(CSlice path, const DbKey &db_key) {
TRY_STATUS(db.exec(PSLICE() << "PRAGMA key = " << key));
}
if (db.is_encrypted()) {
return Status::Error("Wrong key");
return Status::Error("Wrong key or database is corrupted");
}
return std::move(db);
}

View File

@ -59,7 +59,7 @@ class SqliteDb {
static Status destroy(Slice path) TD_WARN_UNUSED_RESULT;
// Anyway we can't change the key on the fly, so static functions is more than enough
// Anyway we can't change the key on the fly, so having static functions is more than enough
static Result<SqliteDb> open_with_key(CSlice path, const DbKey &db_key);
static Status change_key(CSlice path, const DbKey &new_db_key, const DbKey &old_db_key);