From 90d271709f5b0e8698f746c1b2ec7972007b1a11 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 18 Mar 2016 16:08:00 -0700 Subject: [core] Add additional logging for exceptions during database connection / creation Refs #4382 --- platform/default/mbgl/storage/offline_database.cpp | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp index e1cd693662..43f7abaf9d 100644 --- a/platform/default/mbgl/storage/offline_database.cpp +++ b/platform/default/mbgl/storage/offline_database.cpp @@ -58,23 +58,36 @@ void OfflineDatabase::ensureSchema() { removeExisting(); connect(ReadWrite | Create); } catch (mapbox::sqlite::Exception& ex) { - if (ex.code == SQLITE_CANTOPEN) { - connect(ReadWrite | Create); - } else if (ex.code == SQLITE_NOTADB) { - removeExisting(); + if (ex.code != SQLITE_CANTOPEN && ex.code != SQLITE_NOTADB) { + Log::Error(Event::Database, "Unexpected error connecting to database: %s", ex.what()); + throw; + } + + try { + if (ex.code == SQLITE_NOTADB) { + removeExisting(); + } connect(ReadWrite | Create); + } catch (...) { + Log::Error(Event::Database, "Unexpected error creating database: %s", util::toString(std::current_exception()).c_str()); + throw; } } } - #include "offline_schema.cpp.include" + try { + #include "offline_schema.cpp.include" - connect(ReadWrite | Create); + connect(ReadWrite | Create); - // If you change the schema you must write a migration from the previous version. - db->exec("PRAGMA auto_vacuum = INCREMENTAL"); - db->exec(schema); - db->exec("PRAGMA user_version = 3"); + // If you change the schema you must write a migration from the previous version. + db->exec("PRAGMA auto_vacuum = INCREMENTAL"); + db->exec(schema); + db->exec("PRAGMA user_version = 3"); + } catch (...) { + Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str()); + throw; + } } int OfflineDatabase::userVersion() { -- cgit v1.2.1