aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrski <rom.skiad@gmail.com>2022-12-23 02:33:32 +0200
committerrski <rom.skiad@gmail.com>2022-12-23 02:55:51 +0200
commitd034ed1891e66d63f1eae90444a516a931ebadc2 (patch)
tree2eee163519a620f754637bd18f8a1db62ad7dd9f
parentc9eee5a84d91e974b09623e01d12586e7026f1ce (diff)
src/libstore: Print the reason opening the DB failed
Without this, the error is lost, and it makes for a hard to debug situation. Also remove some of the busyness inside the sqlite_open_v2 args. The errcode returned is not the extended one. The only way to make open return an extended code, would be to add SQLITE_OPEN_EXRESCODE to the flags. In the future it might be worth making this change, which would also simplify the existing SQLiteError code.
-rw-r--r--src/libstore/sqlite.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index 6c350888f..353dff9fa 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -47,9 +47,13 @@ SQLite::SQLite(const Path & path, bool create)
// `unix-dotfile` is needed on NFS file systems and on Windows' Subsystem
// for Linux (WSL) where useSQLiteWAL should be false by default.
const char *vfs = settings.useSQLiteWAL ? 0 : "unix-dotfile";
- if (sqlite3_open_v2(path.c_str(), &db,
- SQLITE_OPEN_READWRITE | (create ? SQLITE_OPEN_CREATE : 0), vfs) != SQLITE_OK)
- throw Error("cannot open SQLite database '%s'", path);
+ int flags = SQLITE_OPEN_READWRITE;
+ if (create) flags |= SQLITE_OPEN_CREATE;
+ int ret = sqlite3_open_v2(path.c_str(), &db, flags, vfs);
+ if (ret != SQLITE_OK) {
+ const char * err = sqlite3_errstr(ret);
+ throw Error("cannot open SQLite database '%s': %s", path, err);
+ }
if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
SQLiteError::throw_(db, "setting timeout");