1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-12 22:57:43 +02:00

Bug2596: Error dialogs opening unreadable project should not be blank

This commit is contained in:
Paul Licameli 2020-11-24 12:38:19 -05:00
parent 54359fbefd
commit 5ebfe4670c
4 changed files with 34 additions and 25 deletions

View File

@ -38,8 +38,11 @@ static const char *FastConfig =
"PRAGMA <schema>.synchronous = OFF;" "PRAGMA <schema>.synchronous = OFF;"
"PRAGMA <schema>.journal_mode = OFF;"; "PRAGMA <schema>.journal_mode = OFF;";
DBConnection::DBConnection(const std::weak_ptr<AudacityProject> &pProject) DBConnection::DBConnection(
const std::weak_ptr<AudacityProject> &pProject,
const std::shared_ptr<DBConnectionErrors> &pErrors)
: mpProject{ pProject } : mpProject{ pProject }
, mpErrors{ pErrors }
{ {
mDB = nullptr; mDB = nullptr;
mBypass = false; mBypass = false;
@ -63,21 +66,21 @@ bool DBConnection::ShouldBypass()
void DBConnection::SetError( void DBConnection::SetError(
const TranslatableString &msg, const TranslatableString &libraryError) const TranslatableString &msg, const TranslatableString &libraryError)
{ {
mLastError = msg; mpErrors->mLastError = msg;
mLibraryError = libraryError; mpErrors->mLibraryError = libraryError;
} }
void DBConnection::SetDBError( void DBConnection::SetDBError(
const TranslatableString &msg, const TranslatableString &libraryError) const TranslatableString &msg, const TranslatableString &libraryError)
{ {
mLastError = msg; mpErrors->mLastError = msg;
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug()); wxLogDebug(wxT("SQLite error: %s"), mpErrors->mLastError.Debug());
printf(" Lib error: %s", mLastError.Debug().mb_str().data()); printf(" Lib error: %s", mpErrors->mLastError.Debug().mb_str().data());
mLibraryError = libraryError.empty() mpErrors->mLibraryError = libraryError.empty()
? Verbatim(sqlite3_errmsg(DB())) : libraryError; ? Verbatim(sqlite3_errmsg(DB())) : libraryError;
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug()); wxLogDebug(wxT(" Lib error: %s"), mpErrors->mLibraryError.Debug());
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data()); printf(" Lib error: %s", mpErrors->mLibraryError.Debug().mb_str().data());
wxASSERT(false); wxASSERT(false);
} }

View File

@ -26,11 +26,19 @@ struct sqlite3_stmt;
class wxString; class wxString;
class AudacityProject; class AudacityProject;
struct DBConnectionErrors
{
TranslatableString mLastError;
TranslatableString mLibraryError;
};
class DBConnection class DBConnection
{ {
public: public:
explicit
DBConnection(const std::weak_ptr<AudacityProject> &pProject); DBConnection(
const std::weak_ptr<AudacityProject> &pProject,
const std::shared_ptr<DBConnectionErrors> &pErrors);
~DBConnection(); ~DBConnection();
bool Open(const char *fileName); bool Open(const char *fileName);
@ -79,11 +87,6 @@ public:
const TranslatableString &msg, const TranslatableString &msg,
const TranslatableString &libraryError = {} ); 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);
@ -103,8 +106,7 @@ private:
std::map<enum StatementID, sqlite3_stmt *> mStatements; std::map<enum StatementID, sqlite3_stmt *> mStatements;
TranslatableString mLastError; std::shared_ptr<DBConnectionErrors> mpErrors;
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

@ -247,6 +247,7 @@ const ProjectFileIO &ProjectFileIO::Get( const AudacityProject &project )
ProjectFileIO::ProjectFileIO(AudacityProject &project) ProjectFileIO::ProjectFileIO(AudacityProject &project)
: mProject{ project } : mProject{ project }
, mpErrors{ std::make_shared<DBConnectionErrors>() }
{ {
mPrevConn = nullptr; mPrevConn = nullptr;
@ -318,7 +319,8 @@ bool ProjectFileIO::OpenConnection(FilePath fileName /* = {} */)
} }
// Pass weak_ptr to project into DBConnection constructor // Pass weak_ptr to project into DBConnection constructor
curConn = std::make_unique<DBConnection>(mProject.shared_from_this()); curConn = std::make_unique<DBConnection>(
mProject.shared_from_this(), mpErrors);
if (!curConn->Open(fileName)) if (!curConn->Open(fileName))
{ {
curConn.reset(); curConn.reset();
@ -2049,7 +2051,8 @@ bool ProjectFileIO::SaveProject(
} }
// Open the newly created database // Open the newly created database
Connection newConn = std::make_unique<DBConnection>(mProject.shared_from_this()); Connection newConn = std::make_unique<DBConnection>(
mProject.shared_from_this(), mpErrors);
// NOTE: There is a noticeable delay here when dealing with large multi-hour // NOTE: There is a noticeable delay here when dealing with large multi-hour
// projects that we just created. The delay occurs in Open() when it // projects that we just created. The delay occurs in Open() when it
@ -2270,14 +2273,12 @@ wxLongLong ProjectFileIO::GetFreeDiskSpace() const
const TranslatableString &ProjectFileIO::GetLastError() const TranslatableString &ProjectFileIO::GetLastError()
{ {
auto &currConn = CurrConn(); return mpErrors->mLastError;
return currConn->GetLastError();
} }
const TranslatableString &ProjectFileIO::GetLibraryError() const TranslatableString &ProjectFileIO::GetLibraryError()
{ {
auto &currConn = CurrConn(); return mpErrors->mLibraryError;
return currConn->GetLibraryError();
} }
void ProjectFileIO::SetError( void ProjectFileIO::SetError(

View File

@ -25,6 +25,7 @@ struct sqlite3_value;
class AudacityProject; class AudacityProject;
class DBConnection; class DBConnection;
struct DBConnectionErrors;
class ProjectSerializer; class ProjectSerializer;
class SqliteSampleBlock; class SqliteSampleBlock;
class TrackList; class TrackList;
@ -253,6 +254,8 @@ private:
// non-static data members // non-static data members
AudacityProject &mProject; AudacityProject &mProject;
std::shared_ptr<DBConnectionErrors> mpErrors;
// The project's file path // The project's file path
FilePath mFileName; FilePath mFileName;