diff --git a/tddb/td/db/SqliteConnectionSafe.h b/tddb/td/db/SqliteConnectionSafe.h index 6e45e79e..03adff94 100644 --- a/tddb/td/db/SqliteConnectionSafe.h +++ b/tddb/td/db/SqliteConnectionSafe.h @@ -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(); diff --git a/tddb/td/db/SqliteDb.cpp b/tddb/td/db/SqliteDb.cpp index 81981819..6a07f297 100644 --- a/tddb/td/db/SqliteDb.cpp +++ b/tddb/td/db/SqliteDb.cpp @@ -156,7 +156,7 @@ Result 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); } diff --git a/tddb/td/db/SqliteDb.h b/tddb/td/db/SqliteDb.h index 40137464..8991bab2 100644 --- a/tddb/td/db/SqliteDb.h +++ b/tddb/td/db/SqliteDb.h @@ -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 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);