From 1f9512a2b23a0d404aadefd653d560259779cbec Mon Sep 17 00:00:00 2001 From: bsimmers Date: Tue, 29 Apr 2014 13:00:36 -0700 Subject: [PATCH] More better error messages when repo fails to init schema Summary: We weren't plumbing through the sqlite error when the schema failed to init. Reviewed By: @jdelong Differential Revision: D1302092 --- hphp/runtime/vm/repo.cpp | 19 ++++++++++++------- hphp/runtime/vm/repo.h | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/hphp/runtime/vm/repo.cpp b/hphp/runtime/vm/repo.cpp index f2f57f94dad..b90d6e0ef7a 100644 --- a/hphp/runtime/vm/repo.cpp +++ b/hphp/runtime/vm/repo.cpp @@ -588,11 +588,12 @@ bool Repo::openCentral(const char* rawPath, std::string& errorMsg) { // attempt writing to the database. Therefore, tell initSchema() to verify // that the database is writable. bool centralWritable = true; - if (initSchema(RepoIdCentral, centralWritable) || !centralWritable) { + if (initSchema(RepoIdCentral, centralWritable, errorMsg) || + !centralWritable) { TRACE(1, "Repo::initSchema() failed for candidate central repo '%s'\n", repoPath.c_str()); - errorMsg = folly::format("Failed to initialize schema in {}", - repoPath).str(); + errorMsg = folly::format("Failed to initialize schema in {}: {}", + repoPath, errorMsg).str(); return true; } m_centralRepo = repoPath; @@ -646,7 +647,10 @@ void Repo::attachLocal(const char* path, bool isWritable) { } catch (RepoExc& re) { return; } - if (initSchema(RepoIdLocal, isWritable)) { + + std::string error; + if (initSchema(RepoIdLocal, isWritable, error)) { + FTRACE(1, "Local repo {} failed to init schema: {}\n", repoPath, error); return; } m_localRepo = repoPath; @@ -724,9 +728,9 @@ void Repo::setTextPragma(int repoId, const char* name, const char* val) { } } -bool Repo::initSchema(int repoId, bool& isWritable) { +bool Repo::initSchema(int repoId, bool& isWritable, std::string& errorMsg) { if (!schemaExists(repoId)) { - if (createSchema(repoId)) { + if (createSchema(repoId, errorMsg)) { // Check whether this failure is due to losing the schema // initialization race with another process. if (!schemaExists(repoId)) { @@ -764,7 +768,7 @@ bool Repo::schemaExists(int repoId) { return true; } -bool Repo::createSchema(int repoId) { +bool Repo::createSchema(int repoId, std::string& errorMsg) { try { RepoTxn txn(*this); { @@ -799,6 +803,7 @@ bool Repo::createSchema(int repoId) { txn.commit(); } catch (RepoExc& re) { + errorMsg = re.what(); return true; } return false; diff --git a/hphp/runtime/vm/repo.h b/hphp/runtime/vm/repo.h index e640d6c9f2b..8a8336c9299 100644 --- a/hphp/runtime/vm/repo.h +++ b/hphp/runtime/vm/repo.h @@ -200,9 +200,9 @@ public: void setIntPragma(int repoId, const char* name, int val); void getTextPragma(int repoId, const char* name, std::string& val); void setTextPragma(int repoId, const char* name, const char* val); - bool initSchema(int repoId, bool& isWritable); + bool initSchema(int repoId, bool& isWritable, std::string& errorMsg); bool schemaExists(int repoId); - bool createSchema(int repoId); + bool createSchema(int repoId, std::string& errorMsg); bool writable(int repoId); private: -- 2.11.4.GIT