about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-02-28T12·20+0100
committerEelco Dolstra <edolstra@gmail.com>2017-02-28T12·20+0100
commit80027144ae765544aa96d9c38dc2dd345bcf703d (patch)
tree98450605ebc7171c03e4848d4cb479a191a5f3b3
parent7251d048fa812d2551b7003bc9f13a8f5d4c95a5 (diff)
In SQLite errors, include the database path
This is necessary because we have multiple SQLite databases (e.g. the
binary cache cache).
-rw-r--r--src/libstore/sqlite.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index 0197b091cd12..7d656121249e 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -8,13 +8,17 @@ namespace nix {
 [[noreturn]] void throwSQLiteError(sqlite3 * db, const format & f)
 {
     int err = sqlite3_errcode(db);
+
+    auto path = sqlite3_db_filename(db, nullptr);
+    if (!path) path = "(in-memory)";
+
     if (err == SQLITE_BUSY || err == SQLITE_PROTOCOL) {
         if (err == SQLITE_PROTOCOL)
-            printError("warning: SQLite database is busy (SQLITE_PROTOCOL)");
+            printError("warning: SQLite database ‘%s’ is busy (SQLITE_PROTOCOL)", path);
         else {
             static bool warned = false;
             if (!warned) {
-                printError("warning: SQLite database is busy");
+                printError("warning: SQLite database ‘%s’ is busy", path);
                 warned = true;
             }
         }
@@ -29,10 +33,10 @@ namespace nix {
 #else
         sleep(1);
 #endif
-        throw SQLiteBusy(format("%1%: %2%") % f.str() % sqlite3_errmsg(db));
+        throw SQLiteBusy("%s: %s (in ‘%s’)", f.str(), sqlite3_errstr(err), path);
     }
     else
-        throw SQLiteError(format("%1%: %2%") % f.str() % sqlite3_errmsg(db));
+        throw SQLiteError("%s: %s (in ‘%s’)", f.str(), sqlite3_errstr(err), path);
 }
 
 SQLite::SQLite(const Path & path)