Add clickable docs url on error (#806)

This commit is contained in:
Vladyslav Miachkov 2024-05-25 13:00:51 +03:00 committed by GitHub
parent a0c06048cd
commit b027fff103
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 173 additions and 104 deletions

View file

@ -8,7 +8,6 @@
#include <QtConcurrent>
#include "core/controllers/vpnConfigurationController.h"
#include "core/errorstrings.h"
#include "version.h"
ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &serversModel,
@ -30,7 +29,7 @@ ConnectionController::ConnectionController(const QSharedPointer<ServersModel> &s
connect(&m_apiController, &ApiController::configUpdated, this,
static_cast<void (ConnectionController::*)(const bool, const QJsonObject &, const int)>(&ConnectionController::openConnection));
connect(&m_apiController, &ApiController::errorOccurred, this, &ConnectionController::connectionErrorOccurred);
connect(&m_apiController, qOverload<ErrorCode>(&ApiController::errorOccurred), this, qOverload<ErrorCode>(&ConnectionController::connectionErrorOccurred));
m_state = Vpn::ConnectionState::Disconnected;
}
@ -40,7 +39,7 @@ void ConnectionController::openConnection()
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
if (!Utils::processIsRunning(Utils::executable(SERVICE_NAME, false), true))
{
emit connectionErrorOccurred(errorString(ErrorCode::AmneziaServiceNotRunning));
emit connectionErrorOccurred(ErrorCode::AmneziaServiceNotRunning);
return;
}
#endif
@ -63,9 +62,9 @@ void ConnectionController::closeConnection()
emit disconnectFromVpn();
}
QString ConnectionController::getLastConnectionError()
ErrorCode ConnectionController::getLastConnectionError()
{
return errorString(m_vpnConnection->lastError());
return m_vpnConnection->lastError();
}
void ConnectionController::onConnectionStateChanged(Vpn::ConnectionState state)
@ -218,7 +217,7 @@ void ConnectionController::openConnection(const bool updateConfig, const QJsonOb
ServerCredentials credentials = m_serversModel->getServerCredentials(serverIndex);
ErrorCode errorCode = updateProtocolConfig(container, credentials, containerConfig, serverController);
if (errorCode != ErrorCode::NoError) {
emit connectionErrorOccurred(errorString(errorCode));
emit connectionErrorOccurred(errorCode);
return;
}

View file

@ -34,7 +34,7 @@ public slots:
void openConnection();
void closeConnection();
QString getLastConnectionError();
ErrorCode getLastConnectionError();
void onConnectionStateChanged(Vpn::ConnectionState state);
void onCurrentContainerUpdated();
@ -50,6 +50,7 @@ signals:
void connectionStateChanged();
void connectionErrorOccurred(const QString &errorMessage);
void connectionErrorOccurred(ErrorCode errorCode);
void reconnectWithUpdatedContainer(const QString &message);
void noInstalledContainers();

View file

@ -9,7 +9,6 @@
#include <QStandardPaths>
#include "core/controllers/vpnConfigurationController.h"
#include "core/errorstrings.h"
#include "systemController.h"
#ifdef Q_OS_ANDROID
#include "platforms/android/android_utils.h"
@ -101,7 +100,7 @@ void ExportController::generateConnectionConfig(const QString &clientName)
errorCode = m_clientManagementModel->appendClient(container, credentials, containerConfig, clientName, serverController);
if (errorCode != ErrorCode::NoError) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -171,7 +170,7 @@ void ExportController::generateOpenVpnConfig(const QString &clientName)
}
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -189,7 +188,7 @@ void ExportController::generateWireGuardConfig(const QString &clientName)
QJsonObject nativeConfig;
ErrorCode errorCode = generateNativeConfig(DockerContainer::WireGuard, clientName, Proto::WireGuard, nativeConfig);
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -209,7 +208,7 @@ void ExportController::generateAwgConfig(const QString &clientName)
QJsonObject nativeConfig;
ErrorCode errorCode = generateNativeConfig(DockerContainer::Awg, clientName, Proto::Awg, nativeConfig);
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -237,7 +236,7 @@ void ExportController::generateShadowSocksConfig()
}
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -263,7 +262,7 @@ void ExportController::generateCloakConfig()
QJsonObject nativeConfig;
ErrorCode errorCode = generateNativeConfig(DockerContainer::Cloak, "", Proto::Cloak, nativeConfig);
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -283,7 +282,7 @@ void ExportController::generateXrayConfig()
QJsonObject nativeConfig;
ErrorCode errorCode = generateNativeConfig(DockerContainer::Xray, "", Proto::Xray, nativeConfig);
if (errorCode) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
return;
}
@ -320,7 +319,7 @@ void ExportController::updateClientManagementModel(const DockerContainer contain
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
ErrorCode errorCode = m_clientManagementModel->updateModel(container, credentials, serverController);
if (errorCode != ErrorCode::NoError) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
}
}
@ -330,7 +329,7 @@ void ExportController::revokeConfig(const int row, const DockerContainer contain
ErrorCode errorCode =
m_clientManagementModel->revokeClient(row, container, credentials, m_serversModel->getProcessedServerIndex(), serverController);
if (errorCode != ErrorCode::NoError) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
}
}
@ -339,7 +338,7 @@ void ExportController::renameClient(const int row, const QString &clientName, co
QSharedPointer<ServerController> serverController(new ServerController(m_settings));
ErrorCode errorCode = m_clientManagementModel->renameClient(row, clientName, container, credentials, serverController);
if (errorCode != ErrorCode::NoError) {
emit exportErrorOccurred(errorString(errorCode));
emit exportErrorOccurred(errorCode);
}
}

View file

@ -49,6 +49,7 @@ public slots:
signals:
void generateConfig(int type);
void exportErrorOccurred(const QString &errorMessage);
void exportErrorOccurred(ErrorCode errorCode);
void exportConfigChanged();

View file

@ -6,7 +6,6 @@
#include <QRandomGenerator>
#include <QStandardPaths>
#include "core/errorstrings.h"
#ifdef Q_OS_ANDROID
#include "platforms/android/android_controller.h"
#endif
@ -221,7 +220,7 @@ void ImportController::importConfig()
} else if (m_config.contains(config_key::configVersion)) {
quint16 crc = qChecksum(QJsonDocument(m_config).toJson());
if (m_serversModel->isServerFromApiAlreadyExists(crc)) {
emit importErrorOccurred(errorString(ErrorCode::ApiConfigAlreadyAdded), true);
emit importErrorOccurred(ErrorCode::ApiConfigAlreadyAdded, true);
} else {
m_config.insert(config_key::crc, crc);
@ -231,7 +230,7 @@ void ImportController::importConfig()
} else {
qDebug() << "Failed to import profile";
qDebug().noquote() << QJsonDocument(m_config).toJson();
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false);
emit importErrorOccurred(ErrorCode::ImportInvalidConfigError, false);
}
m_config = {};
@ -308,7 +307,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
hostName = hostNameAndPortMatch.captured(1);
} else {
qDebug() << "Key parameter 'Endpoint' is missing";
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false);
emit importErrorOccurred(ErrorCode::ImportInvalidConfigError, false);
return QJsonObject();
}
@ -334,7 +333,7 @@ QJsonObject ImportController::extractWireGuardConfig(const QString &data)
lastConfig[config_key::server_pub_key] = configMap.value("PublicKey");
} else {
qDebug() << "One of the key parameters is missing (PrivateKey, Address, PublicKey)";
emit importErrorOccurred(errorString(ErrorCode::ImportInvalidConfigError), false);
emit importErrorOccurred(ErrorCode::ImportInvalidConfigError, false);
return QJsonObject();
}

View file

@ -54,6 +54,7 @@ public slots:
signals:
void importFinished();
void importErrorOccurred(const QString &errorMessage, bool goToPageHome);
void importErrorOccurred(ErrorCode errorCode, bool goToPageHome);
void qrDecodingFinished();

View file

@ -9,7 +9,6 @@
#include "core/controllers/serverController.h"
#include "core/controllers/vpnConfigurationController.h"
#include "core/errorstrings.h"
#include "core/networkUtilities.h"
#include "logger.h"
#include "ui/models/protocols/awgConfigModel.h"
@ -149,7 +148,7 @@ void InstallController::install(DockerContainer container, int port, TransportPr
QMap<DockerContainer, QJsonObject> installedContainers;
ErrorCode errorCode = getAlreadyInstalledContainers(serverCredentials, serverController, installedContainers);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
@ -158,7 +157,7 @@ void InstallController::install(DockerContainer container, int port, TransportPr
if (!installedContainers.contains(container)) {
errorCode = serverController->setupContainer(serverCredentials, container, config);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
@ -169,7 +168,7 @@ void InstallController::install(DockerContainer container, int port, TransportPr
}
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
@ -204,7 +203,7 @@ void InstallController::installServer(const DockerContainer container, const QMa
auto errorCode = vpnConfigurationController.createProtocolConfigForContainer(m_processedServerCredentials, iterator.key(),
containerConfig);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
containerConfigs.append(containerConfig);
@ -212,7 +211,7 @@ void InstallController::installServer(const DockerContainer container, const QMa
errorCode = m_clientManagementModel->appendClient(iterator.key(), serverCredentials, containerConfig,
QString("Admin [%1]").arg(QSysInfo::prettyProductName()), serverController);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
} else {
@ -244,7 +243,7 @@ void InstallController::installContainer(const DockerContainer container, const
auto errorCode =
vpnConfigurationController.createProtocolConfigForContainer(serverCredentials, iterator.key(), containerConfig);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
m_serversModel->addContainerConfig(iterator.key(), containerConfig);
@ -252,7 +251,7 @@ void InstallController::installContainer(const DockerContainer container, const
errorCode = m_clientManagementModel->appendClient(iterator.key(), serverCredentials, containerConfig,
QString("Admin [%1]").arg(QSysInfo::prettyProductName()), serverController);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
} else {
@ -310,7 +309,7 @@ void InstallController::scanServerForInstalledContainers()
auto errorCode =
vpnConfigurationController.createProtocolConfigForContainer(serverCredentials, container, containerConfig);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
m_serversModel->addContainerConfig(container, containerConfig);
@ -319,7 +318,7 @@ void InstallController::scanServerForInstalledContainers()
QString("Admin [%1]").arg(QSysInfo::prettyProductName()),
serverController);
if (errorCode) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return;
}
} else {
@ -334,7 +333,7 @@ void InstallController::scanServerForInstalledContainers()
return;
}
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
}
ErrorCode InstallController::getAlreadyInstalledContainers(const ServerCredentials &credentials,
@ -515,7 +514,7 @@ void InstallController::updateContainer(QJsonObject config)
return;
}
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
}
void InstallController::rebootProcessedServer()
@ -528,7 +527,7 @@ void InstallController::rebootProcessedServer()
if (errorCode == ErrorCode::NoError) {
emit rebootProcessedServerFinished(tr("Server '%1' was rebooted").arg(serverName));
} else {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
}
}
@ -552,7 +551,7 @@ void InstallController::removeAllContainers()
emit removeAllContainersFinished(tr("All containers from server '%1' have been removed").arg(serverName));
return;
}
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
}
void InstallController::removeProcessedContainer()
@ -570,7 +569,7 @@ void InstallController::removeProcessedContainer()
emit removeProcessedContainerFinished(tr("%1 has been removed from the server '%2'").arg(containerName, serverName));
return;
}
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
}
void InstallController::removeApiConfig(const int serverIndex)
@ -738,7 +737,7 @@ bool InstallController::checkSshConnection(QSharedPointer<ServerController> serv
if (errorCode == ErrorCode::NoError) {
m_processedServerCredentials.secretData = decryptedPrivateKey;
} else {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return false;
}
}
@ -747,7 +746,7 @@ bool InstallController::checkSshConnection(QSharedPointer<ServerController> serv
output = serverController->checkSshConnection(m_processedServerCredentials, errorCode);
if (errorCode != ErrorCode::NoError) {
emit installationErrorOccurred(errorString(errorCode));
emit installationErrorOccurred(errorCode);
return false;
} else {
if (output.contains(tr("Please login as the user"))) {

View file

@ -64,6 +64,7 @@ signals:
void removeProcessedContainerFinished(const QString &finishedMessage);
void installationErrorOccurred(const QString &errorMessage);
void installationErrorOccurred(ErrorCode errorCode);
void serverAlreadyExists(int serverIndex);

View file

@ -1,4 +1,6 @@
#include "pageController.h"
#include "utils/converter.h"
#include "core/errorstrings.h"
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#include <QGuiApplication>
@ -38,6 +40,8 @@ PageController::PageController(const QSharedPointer<ServersModel> &serversModel,
connect(this, &PageController::raiseMainWindow, []() { setDockIconVisible(true); });
connect(this, &PageController::hideMainWindow, []() { setDockIconVisible(false); });
#endif
connect(this, qOverload<ErrorCode>(&PageController::showErrorMessage), this, &PageController::onShowErrorMessage);
m_isTriggeredByConnectButton = false;
}
@ -161,3 +165,13 @@ int PageController::getDrawerDepth()
{
return m_drawerDepth;
}
void PageController::onShowErrorMessage(ErrorCode errorCode)
{
const auto fullErrorMessage = errorString(errorCode);
const auto errorMessage = fullErrorMessage.mid(fullErrorMessage.indexOf(". ") + 1); // remove ErrorCode %1.
const auto errorUrl = QStringLiteral("https://docs.amnezia.org/troubleshooting/error-codes/#error-%1-%2").arg(static_cast<int>(errorCode)).arg(utils::enumToString(errorCode).toLower());
const auto fullMessage = QStringLiteral("<a href=\"%1\" style=\"color: #FBB26A;\">ErrorCode: %2</a>. %3").arg(errorUrl).arg(static_cast<int>(errorCode)).arg(errorMessage);
emit showErrorMessage(fullMessage);
}

View file

@ -4,6 +4,7 @@
#include <QObject>
#include <QQmlEngine>
#include "core/defs.h"
#include "ui/models/servers_model.h"
namespace PageLoader
@ -93,6 +94,9 @@ public slots:
void setDrawerDepth(const int depth);
int getDrawerDepth();
private slots:
void onShowErrorMessage(amnezia::ErrorCode errorCode);
signals:
void goToPage(PageLoader::PageEnum page, bool slide = true);
void goToStartPage();
@ -107,6 +111,7 @@ signals:
void restorePageHomeState(bool isContainerInstalled = false);
void replaceStartPage();
void showErrorMessage(amnezia::ErrorCode);
void showErrorMessage(const QString &errorMessage);
void showNotificationMessage(const QString &message);