1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-23 09:20:16 +01:00

Demote error message storage from ProjectFileIO into DBConnection

This commit is contained in:
Paul Licameli
2020-09-02 14:59:03 -04:00
parent c9dec8f5a9
commit eb7e67623e
4 changed files with 74 additions and 40 deletions

View File

@@ -55,6 +55,28 @@ bool DBConnection::ShouldBypass()
return mBypass; return mBypass;
} }
void DBConnection::SetError(
const TranslatableString &msg, const TranslatableString &libraryError)
{
mLastError = msg;
mLibraryError = libraryError;
}
void DBConnection::SetDBError(
const TranslatableString &msg, const TranslatableString &libraryError)
{
mLastError = msg;
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug());
printf(" Lib error: %s", mLastError.Debug().mb_str().data());
mLibraryError = libraryError.empty()
? Verbatim(sqlite3_errmsg(DB())) : libraryError;
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug());
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data());
wxASSERT(false);
}
bool DBConnection::Open(const char *fileName) bool DBConnection::Open(const char *fileName)
{ {
wxASSERT(mDB == nullptr); wxASSERT(mDB == nullptr);

View File

@@ -69,6 +69,21 @@ public:
void SetBypass( bool bypass ); void SetBypass( bool bypass );
bool ShouldBypass(); bool ShouldBypass();
//! Just set stored errors
void SetError(
const TranslatableString &msg,
const TranslatableString &libraryError = {} );
//! Set stored errors and write to log; and default libraryError to what database library reports
void SetDBError(
const TranslatableString &msg,
const TranslatableString &libraryError = {} );
const TranslatableString &GetLastError() const
{ return mLastError; }
const TranslatableString &GetLibraryError() const
{ return mLibraryError; }
private: private:
bool ModeConfig(sqlite3 *db, const char *schema, const char *config); bool ModeConfig(sqlite3 *db, const char *schema, const char *config);
@@ -88,6 +103,9 @@ private:
std::map<enum StatementID, sqlite3_stmt *> mStatements; std::map<enum StatementID, sqlite3_stmt *> mStatements;
TranslatableString mLastError;
TranslatableString mLibraryError;
// Bypass transactions if database will be deleted after close // Bypass transactions if database will be deleted after close
bool mBypass; bool mBypass;
}; };

View File

@@ -507,9 +507,9 @@ int ProjectFileIO::Exec(const char *query, const ExecCB &callback)
if (rc != SQLITE_ABORT && errmsg) if (rc != SQLITE_ABORT && errmsg)
{ {
SetDBError( SetDBError(
XO("Failed to execute a project file command:\n\n%s").Format(query) XO("Failed to execute a project file command:\n\n%s").Format(query),
Verbatim(errmsg)
); );
mLibraryError = Verbatim(errmsg);
} }
if (errmsg) if (errmsg)
{ {
@@ -1769,9 +1769,8 @@ bool ProjectFileIO::ImportProject(const FilePath &fileName)
if (!xmlFile.ParseString(this, output.GetString())) if (!xmlFile.ParseString(this, output.GetString()))
{ {
SetError( SetError(
XO("Unable to parse project information.") XO("Unable to parse project information."), xmlFile.GetErrorStr()
); );
mLibraryError = xmlFile.GetErrorStr();
return false; return false;
} }
@@ -1846,9 +1845,9 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
if (!success) if (!success)
{ {
SetError( SetError(
XO("Unable to parse project information.") XO("Unable to parse project information."),
xmlFile.GetErrorStr()
); );
mLibraryError = xmlFile.GetErrorStr();
return false; return false;
} }
@@ -2122,37 +2121,30 @@ wxLongLong ProjectFileIO::GetFreeDiskSpace() const
return -1; return -1;
} }
const TranslatableString &ProjectFileIO::GetLastError() const const TranslatableString &ProjectFileIO::GetLastError()
{
return mLastError;
}
const TranslatableString &ProjectFileIO::GetLibraryError() const
{
return mLibraryError;
}
void ProjectFileIO::SetError(const TranslatableString &msg)
{
mLastError = msg;
mLibraryError = {};
}
void ProjectFileIO::SetDBError(const TranslatableString &msg)
{ {
auto &currConn = CurrConn(); auto &currConn = CurrConn();
mLastError = msg; return currConn->GetLastError();
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug()); }
printf(" Lib error: %s", mLastError.Debug().mb_str().data());
if (currConn) const TranslatableString &ProjectFileIO::GetLibraryError()
{ {
mLibraryError = Verbatim(sqlite3_errmsg(currConn->DB())); auto &currConn = CurrConn();
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug()); return currConn->GetLibraryError();
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data()); }
}
wxASSERT(false); void ProjectFileIO::SetError(
const TranslatableString &msg, const TranslatableString &libraryError )
{
auto &currConn = CurrConn();
currConn->SetError(msg, libraryError);
}
void ProjectFileIO::SetDBError(
const TranslatableString &msg, const TranslatableString &libraryError)
{
auto &currConn = CurrConn();
currConn->SetDBError(msg, libraryError);
} }
void ProjectFileIO::SetBypass() void ProjectFileIO::SetBypass()

View File

@@ -104,8 +104,8 @@ public:
// specific database. This is the workhorse for the above 3 methods. // specific database. This is the workhorse for the above 3 methods.
static int64_t GetDiskUsage(DBConnection *conn, SampleBlockID blockid); static int64_t GetDiskUsage(DBConnection *conn, SampleBlockID blockid);
const TranslatableString &GetLastError() const; const TranslatableString &GetLastError();
const TranslatableString &GetLibraryError() const; const TranslatableString &GetLibraryError();
// Provides a means to bypass "DELETE"s at shutdown if the database // Provides a means to bypass "DELETE"s at shutdown if the database
// is just going to be deleted anyway. This prevents a noticable // is just going to be deleted anyway. This prevents a noticable
@@ -199,8 +199,13 @@ private:
bool prune = false, bool prune = false,
const std::shared_ptr<TrackList> &tracks = nullptr); const std::shared_ptr<TrackList> &tracks = nullptr);
void SetError(const TranslatableString & msg); //! Just set stored errors
void SetDBError(const TranslatableString & msg); void SetError(const TranslatableString & msg,
const TranslatableString &libraryError = {});
//! Set stored errors and write to log; and default libraryError to what database library reports
void SetDBError(const TranslatableString & msg,
const TranslatableString &libraryError = {});
bool ShouldCompact(const std::shared_ptr<TrackList> &tracks); bool ShouldCompact(const std::shared_ptr<TrackList> &tracks);
@@ -236,9 +241,6 @@ private:
Connection mPrevConn; Connection mPrevConn;
FilePath mPrevFileName; FilePath mPrevFileName;
bool mPrevTemporary; bool mPrevTemporary;
TranslatableString mLastError;
TranslatableString mLibraryError;
}; };
// Make a savepoint (a transaction, possibly nested) with the given name; // Make a savepoint (a transaction, possibly nested) with the given name;