Changed exceptions to std bases

This commit is contained in:
Digital Artifex
2026-08-25 04:42:43 -04:00
parent f3adc14a6e
commit 6541cedc67
3 changed files with 210 additions and 36 deletions
+177 -16
View File
@@ -19,36 +19,197 @@
#ifndef EXCEPTIONS_H #ifndef EXCEPTIONS_H
#define EXCEPTIONS_H #define EXCEPTIONS_H
#include <QString> #include <QString>
#include <exception> #include <string>
#include <filesystem>
#include "komplex_global.h" #include "komplex_global.h"
struct KOMPLEX_EXPORT Exception : std::exception struct KOMPLEX_EXPORT network_exception : std::ios_base::failure
{ {
explicit Exception(const QString &message, quint16 errorCode = 0) network_exception(const std::string &message, const std::string &details, const std::error_code &code) :
: std::exception(), message(message), errorCode(errorCode){} details(details),
std::ios_base::failure(message, code) { }
const QString message; network_exception(const std::string &message, const std::error_code &code) :
const quint16 errorCode; std::ios_base::failure(message, code) { }
network_exception(const QString &message, const QString &details, const std::error_code &code) :
details(details.toStdString()),
std::ios_base::failure(message.toStdString(), code) { }
network_exception(const QString &message, const int code = errno) :
std::ios_base::failure
(
message.toStdString(),
std::error_code
(
code,
std::system_category()
)
) { }
const std::string details;
}; };
struct KOMPLEX_EXPORT NetworkException : Exception struct KOMPLEX_EXPORT file_exception : std::filesystem::filesystem_error
{ {
NetworkException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {} file_exception(const std::string &message, const std::string &details, const std::error_code &code) :
details(details),
std::filesystem::filesystem_error(message, code) { }
file_exception(const std::string &message, const std::error_code &code) :
std::filesystem::filesystem_error(message, code) { }
file_exception(const std::string &message, const int code = errno) :
std::filesystem::filesystem_error
(
message,
std::error_code
(
code,
std::system_category()
)
) { }
file_exception(const std::string &message, const std::string &details, const int code = errno) :
details(details),
std::filesystem::filesystem_error
(
message,
std::error_code
(
code,
std::system_category()
)
) { }
const std::string details;
}; };
struct KOMPLEX_EXPORT FileException : Exception
struct KOMPLEX_EXPORT sql_exception : std::ios_base::failure
{ {
FileException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {} sql_exception(const std::string &message, const std::string &details, const std::error_code &code) :
details(details),
std::ios_base::failure(message, code) { }
sql_exception(const std::string &message, const std::error_code &code) :
std::ios_base::failure(message, code) { }
sql_exception(const std::string &message, const int code = errno) :
std::ios_base::failure
(
message,
std::error_code
(
code,
std::system_category()
)
) { }
const std::string details;
}; };
struct KOMPLEX_EXPORT SqlException : Exception
struct KOMPLEX_EXPORT wallet_exception : std::ios_base::failure
{ {
SqlException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {} wallet_exception(const std::string &message, const std::string &details, const std::error_code &code) :
details(details),
std::ios_base::failure(message, code) { }
wallet_exception(const std::string &message, const std::error_code &code) :
std::ios_base::failure(message, code) { }
wallet_exception(const std::string &message, const std::string &details, const int code = errno) :
details(details),
std::ios_base::failure
(
message,
std::error_code
(
code,
std::system_category()
)
) { }
wallet_exception(const std::string &message, const int code = errno) :
std::ios_base::failure
(
message,
std::error_code
(
code,
std::system_category()
)
) { }
const std::string details;
}; };
struct KOMPLEX_EXPORT WalletException : Exception
struct KOMPLEX_EXPORT process_exception : std::runtime_error
{ {
WalletException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {} process_exception(const std::string &message, const std::string &details, const std::error_code &code) :
details(details),
code(code),
std::runtime_error(message) { }
process_exception(const std::string &message, const std::error_code &code) :
code(code),
std::runtime_error(message) { }
process_exception(const std::string &message, const int code = errno) :
code
(
std::error_code
(
code,
std::system_category()
)
),
std::runtime_error
(
message
) { }
process_exception(const std::string &message, const std::string &details, const int code = errno) :
details(details),
code
(
std::error_code
(
code,
std::system_category()
)
),
std::runtime_error (message) { }
const std::string details;
const std::error_code code;
}; };
struct KOMPLEX_EXPORT ShaderCompilerException : Exception
namespace shader
{ {
ShaderCompilerException(const QString &message, qsizetype errorCode = 0) : Exception(message, errorCode) {} struct KOMPLEX_EXPORT logic_error : std::logic_error
{
logic_error(const std::string &message, const std::string &details, const std::error_code &code) :
details(details),
code(code),
std::logic_error(message) { }
logic_error(const std::string &message, const std::error_code &code) :
code(code),
std::logic_error(message) { }
logic_error(const std::string &message, const std::string &details = {}, const int code = errno) :
code
(
std::error_code
(
code,
std::system_category()
)
),
std::logic_error(message) { }
const std::string details;
const std::error_code code;
}; };
}
#endif // EXCEPTIONS_H #endif // EXCEPTIONS_H
+13 -4
View File
@@ -1,5 +1,6 @@
#include "qwallet.h" #include "qwallet.h"
#include "../3rdparty/qtkeychain/qtkeychain/keychain.h" #include "../3rdparty/qtkeychain/qtkeychain/keychain.h"
#include "common/exceptions.h"
auto QWallet::read(const QString &service, const QString &key) const -> QFuture<QByteArray> auto QWallet::read(const QString &service, const QString &key) const -> QFuture<QByteArray>
{ {
@@ -29,7 +30,11 @@ auto QWallet::read(const QString &service, const QString &key) const -> QFuture<
else else
{ {
m_errorString = qPrintable(j->errorString()); m_errorString = qPrintable(j->errorString());
throw std::exception(); throw wallet_exception
(
QStringLiteral("Wallet read error").toStdString(),
errorString().toStdString()
);
} }
loop.quit(); loop.quit();
@@ -65,11 +70,15 @@ auto QWallet::write(const QString &service, const QString &key, const QByteArray
this, this,
[this, key, &loop, &success](QKeychain::Job *job) [this, key, &loop, &success](QKeychain::Job *job)
{ {
auto j = static_cast<QKeychain::ReadPasswordJob*>(job); auto j = static_cast<QKeychain::WritePasswordJob*>(job);
if (j->error() != QKeychain::NoError) if (j->error() != QKeychain::NoError)
{ {
setErrorString(qPrintable(j->errorString())); setErrorString(qPrintable(j->errorString()));
throw std::exception(); throw wallet_exception
(
QStringLiteral("Wallet write error").toStdString(),
errorString().toStdString()
);
} }
loop.quit(); loop.quit();
@@ -102,7 +111,7 @@ auto QWallet::remove(const QString &service, const QString &key) -> QFuture<void
this, this,
[this, key, &loop, &value](QKeychain::Job *job) [this, key, &loop, &value](QKeychain::Job *job)
{ {
auto j = static_cast<QKeychain::ReadPasswordJob*>(job); auto j = static_cast<QKeychain::DeletePasswordJob*>(job);
if (j->error() != QKeychain::NoError) if (j->error() != QKeychain::NoError)
{ {
m_errorString = qPrintable(j->errorString()); m_errorString = qPrintable(j->errorString());
+19 -15
View File
@@ -130,7 +130,7 @@ auto DownloadManager::downloadImage(const QString &author, const QString &author
if(!packDirectory.mkpath(packUri.toLocalFile())) if(!packDirectory.mkpath(packUri.toLocalFile()))
{ {
throw FileException(QStringLiteral("Could not create directory")); throw file_exception(QStringLiteral("Could not create directory").toStdString());
} }
packDirectory.mkdir(QStringLiteral("images")); packDirectory.mkdir(QStringLiteral("images"));
@@ -148,7 +148,7 @@ auto DownloadManager::downloadImage(const QString &author, const QString &author
if(!packFile.open(QFile::ReadWrite)) if(!packFile.open(QFile::ReadWrite))
{ {
setError(QStringLiteral("File Error"), packFile.errorString()); setError(QStringLiteral("File Error"), packFile.errorString());
throw FileException(packFile.errorString()); throw file_exception(packFile.errorString().toStdString());
} }
QByteArray data = metadata.json().toJson(QJsonDocument::Indented); QByteArray data = metadata.json().toJson(QJsonDocument::Indented);
@@ -156,7 +156,7 @@ auto DownloadManager::downloadImage(const QString &author, const QString &author
if(packFile.write(data) != data.length()) if(packFile.write(data) != data.length())
{ {
setError(QStringLiteral("File Error"), packFile.errorString()); setError(QStringLiteral("File Error"), packFile.errorString());
throw FileException(packFile.errorString()); throw file_exception(packFile.errorString().toStdString());
} }
packFile.close(); packFile.close();
@@ -239,6 +239,8 @@ auto DownloadManager::downloadVideo(const QString &author, const QString &author
( (
[this, author, id](QUrl result) -> QUrl [this, author, id](QUrl result) -> QUrl
{ {
setState(Installing);
ShaderPack metadata; ShaderPack metadata;
metadata.setAuthor(author); metadata.setAuthor(author);
metadata.setType(ShaderPack::Video); metadata.setType(ShaderPack::Video);
@@ -282,7 +284,7 @@ auto DownloadManager::downloadVideo(const QString &author, const QString &author
if(!packFile.open(QFile::ReadWrite)) if(!packFile.open(QFile::ReadWrite))
{ {
setError(QStringLiteral("File Error"), packFile.errorString()); setError(QStringLiteral("File Error"), packFile.errorString());
throw FileException(packFile.errorString()); throw file_exception(packFile.errorString().toStdString());
} }
QByteArray data = metadata.json().toJson(QJsonDocument::Compact); QByteArray data = metadata.json().toJson(QJsonDocument::Compact);
@@ -290,7 +292,7 @@ auto DownloadManager::downloadVideo(const QString &author, const QString &author
if(packFile.write(data) != data.length()) if(packFile.write(data) != data.length())
{ {
setError(QStringLiteral("File Error"), packFile.errorString()); setError(QStringLiteral("File Error"), packFile.errorString());
throw FileException(packFile.errorString()); throw file_exception(packFile.errorString().toStdString());
} }
packFile.close(); packFile.close();
@@ -369,6 +371,7 @@ auto DownloadManager::downloadPack(const QString &id) -> void
QNetworkRequest request(downloadUrl); QNetworkRequest request(downloadUrl);
request.setRawHeader(QByteArray("uuid"), id.toUtf8()); request.setRawHeader(QByteArray("uuid"), id.toUtf8());
QString tempFile(QString("%1.tar.gz").arg(id)); QString tempFile(QString("%1.tar.gz").arg(id));
setState(Downloading);
QFuture<QUrl> downloadUri = download(request, id, Post, tempFile); QFuture<QUrl> downloadUri = download(request, id, Post, tempFile);
@@ -377,7 +380,8 @@ auto DownloadManager::downloadPack(const QString &id) -> void
( (
[this](QUrl result) -> QUrl [this](QUrl result) -> QUrl
{ {
return m_compiler->process(result).result(); setState(Compiling);
return m_compiler->build(result);
} }
) )
.then .then
@@ -414,11 +418,11 @@ auto DownloadManager::downloadPack(const QString &id) -> void
) )
.onFailed .onFailed
( (
[this, tempFile] (const std::logic_error &e) [this, tempFile] (const shader::logic_error &e)
{ {
QFile::remove(QStringLiteral("/tmp/") + tempFile); QFile::remove(QStringLiteral("/tmp/") + tempFile);
reset(); reset();
setError(QStringLiteral("Logic Exception %1"), e.what()); setError(e.what(), QString::fromStdString(e.details));
} }
) )
.onFailed .onFailed
@@ -427,7 +431,7 @@ auto DownloadManager::downloadPack(const QString &id) -> void
{ {
QFile::remove(QStringLiteral("/tmp/") + tempFile); QFile::remove(QStringLiteral("/tmp/") + tempFile);
reset(); reset();
setError(QStringLiteral("Logic Exception %1"), e.what()); setError(QStringLiteral("Exception %1"), e.what());
} }
) )
.onFailed .onFailed
@@ -554,13 +558,13 @@ auto DownloadManager::install(const QUrl &uri) noexcept(false) -> QUrl
if(!m_moveProcess.waitForStarted(3000)) if(!m_moveProcess.waitForStarted(3000))
{ {
qWarning() << QStringLiteral("Could not start copy process: %1").arg(m_moveProcess.readAllStandardError()); qWarning() << QStringLiteral("Could not start copy process: %1").arg(m_moveProcess.readAllStandardError());
throw FileException(QStringLiteral("Could not start install process")); throw file_exception(QStringLiteral("Could not start install process").toStdString());
} }
if(!m_moveProcess.waitForFinished()) if(!m_moveProcess.waitForFinished())
{ {
qWarning() << QStringLiteral("Copy process took longer than expected (>30s)"); qWarning() << QStringLiteral("Copy process took longer than expected (>30s)");
throw FileException(QStringLiteral("Install process took longer than expected (>30s)")); throw file_exception(QStringLiteral("Install process took longer than expected (>30s)").toStdString());
} }
return installLocation; return installLocation;
@@ -594,7 +598,7 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
if(manager == nullptr) if(manager == nullptr)
{ {
throw NetworkException throw network_exception
{ {
QStringLiteral("Network Manager reference has already been deleted") QStringLiteral("Network Manager reference has already been deleted")
}; };
@@ -604,7 +608,7 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
if(downloadFile.exists() && !downloadFile.remove()) if(downloadFile.exists() && !downloadFile.remove())
{ {
throw FileException(downloadFile.errorString()); throw file_exception(downloadFile.errorString().toStdString());
} }
QNetworkReply *reply = nullptr; QNetworkReply *reply = nullptr;
@@ -629,7 +633,7 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
{ {
loop.quit(); loop.quit();
throw NetworkException throw network_exception
( (
QStringLiteral("Network Error %1").arg QStringLiteral("Network Error %1").arg
( (
@@ -664,7 +668,7 @@ auto DownloadManager::download(const QNetworkRequest &request, const QString &id
if(!downloadFile.open(QFile::ReadWrite | QFile::Append)) if(!downloadFile.open(QFile::ReadWrite | QFile::Append))
{ {
throw FileException(QStringLiteral("Could not open temp file location")); throw file_exception(QStringLiteral("Could not open temp file location").toStdString());
} }
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());