Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

logic: improve logging if exception occurred while loading project #1004

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/lib/app/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "utilityString.h"
#include "utilityUuid.h"

#include "CppSQLite3.h"

std::shared_ptr<Application> Application::s_instance;
std::string Application::s_uuid;

Expand Down Expand Up @@ -306,20 +308,26 @@ void Application::handleMessage(MessageLoadProject* message)
}
catch (std::exception& e)
{
LOG_ERROR_STREAM(<< "Failed to load project, exception thrown: " << e.what());
MessageStatus(
L"Failed to load project, exception was thrown: " + projectSettingsFilePath.wstr(),
true)
.dispatch();
const std::wstring message = L"Failed to load project at \"" +
projectSettingsFilePath.wstr() + L"\" with exception: " +
utility::decodeFromUtf8(e.what());
LOG_ERROR(message);
MessageStatus(message, true).dispatch();
}
catch (CppSQLite3Exception& e)
{
const std::wstring message = L"Failed to load project at \"" +
projectSettingsFilePath.wstr() + L"\" with sqlite exception: " +
utility::decodeFromUtf8(e.errorMessage());
LOG_ERROR(message);
MessageStatus(message, true).dispatch();
}
catch (...)
{
LOG_ERROR_STREAM(<< "Failed to load project, unknown exception thrown.");
MessageStatus(
L"Failed to load project, unknown exception was thrown: " +
projectSettingsFilePath.wstr(),
true)
.dispatch();
const std::wstring message = L"Failed to load project at \"" +
projectSettingsFilePath.wstr() + L"\" with unknown exception.";
LOG_ERROR(message);
MessageStatus(message, true).dispatch();
}

if (message->refreshMode != REFRESH_NONE)
Expand Down
12 changes: 11 additions & 1 deletion src/lib/data/storage/sqlite/SqliteStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ SqliteStorage::SqliteStorage(const FilePath& dbFilePath): m_dbFilePath(dbFilePat
FileSystem::createDirectory(m_dbFilePath.getParentDirectory());
}

m_database.open(utility::encodeToUtf8(m_dbFilePath.wstr()).c_str());
try
{
m_database.open(utility::encodeToUtf8(m_dbFilePath.wstr()).c_str());
}
catch (CppSQLite3Exception& e)
{
LOG_ERROR(
L"Failed to load database file \"" + m_dbFilePath.wstr() + L"\" with message: " +
utility::decodeFromUtf8(e.errorMessage()));
throw;
}

executeStatement("PRAGMA foreign_keys=ON;");
}
Expand Down