aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2023-01-03 12:44:14 +0100
committerGitHub <noreply@github.com>2023-01-03 12:44:14 +0100
commitae31b5f50f23aa308c69435048ee747543378e2f (patch)
tree6efd445b78245876014cb3b7f9a98d8f8983812a /src
parenta75b7ba30f1e4f8b15e810fd18e63ee9552e0815 (diff)
parentd034ed1891e66d63f1eae90444a516a931ebadc2 (diff)
Merge pull request #7497 from rski/master
src/libstore: Print the reason opening the DB failed
Diffstat (limited to 'src')
-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");