added error code output
This commit is contained in:
parent
5ad54bfdc1
commit
11641c5e22
2 changed files with 120 additions and 101 deletions
|
@ -4,77 +4,92 @@
|
||||||
#include <QMetaEnum>
|
#include <QMetaEnum>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
namespace amnezia {
|
namespace amnezia
|
||||||
|
|
||||||
constexpr const qint16 qrMagicCode = 1984;
|
|
||||||
|
|
||||||
struct ServerCredentials
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
constexpr const qint16 qrMagicCode = 1984;
|
||||||
|
|
||||||
|
struct ServerCredentials
|
||||||
|
{
|
||||||
QString hostName;
|
QString hostName;
|
||||||
QString userName;
|
QString userName;
|
||||||
QString secretData;
|
QString secretData;
|
||||||
int port = 22;
|
int port = 22;
|
||||||
|
|
||||||
bool isValid() const { return !hostName.isEmpty() && !userName.isEmpty() && !secretData.isEmpty() && port > 0; }
|
bool isValid() const
|
||||||
};
|
{
|
||||||
|
return !hostName.isEmpty() && !userName.isEmpty() && !secretData.isEmpty() && port > 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
enum ErrorCode
|
enum ErrorCode {
|
||||||
{
|
|
||||||
// General error codes
|
// General error codes
|
||||||
NoError = 0,
|
NoError = 0,
|
||||||
UnknownError,
|
UnknownError = 1,
|
||||||
InternalError,
|
InternalError = 2,
|
||||||
NotImplementedError,
|
NotImplementedError = 3,
|
||||||
|
|
||||||
// Server errors
|
// Server errors
|
||||||
ServerCheckFailed,
|
ServerCheckFailed = 4,
|
||||||
ServerPortAlreadyAllocatedError,
|
ServerPortAlreadyAllocatedError = 5,
|
||||||
ServerContainerMissingError,
|
ServerContainerMissingError = 6,
|
||||||
ServerDockerFailedError,
|
ServerDockerFailedError = 7,
|
||||||
ServerCancelInstallation,
|
ServerCancelInstallation = 8,
|
||||||
ServerUserNotInSudo,
|
ServerUserNotInSudo = 9,
|
||||||
ServerPacketManagerError,
|
ServerPacketManagerError = 10,
|
||||||
|
|
||||||
// Ssh connection errors
|
// Ssh connection errors
|
||||||
SshRequestDeniedError, SshInterruptedError, SshInternalError,
|
SshRequestDeniedError = 11,
|
||||||
SshPrivateKeyError, SshPrivateKeyFormatError, SshTimeoutError,
|
SshInterruptedError = 12,
|
||||||
|
SshInternalError = 13,
|
||||||
|
SshPrivateKeyError = 14,
|
||||||
|
SshPrivateKeyFormatError = 15,
|
||||||
|
SshTimeoutError = 16,
|
||||||
|
|
||||||
// Ssh sftp errors
|
// Ssh sftp errors
|
||||||
SshSftpEofError, SshSftpNoSuchFileError, SshSftpPermissionDeniedError,
|
SshSftpEofError = 17,
|
||||||
SshSftpFailureError, SshSftpBadMessageError, SshSftpNoConnectionError,
|
SshSftpNoSuchFileError = 18,
|
||||||
SshSftpConnectionLostError, SshSftpOpUnsupportedError, SshSftpInvalidHandleError,
|
SshSftpPermissionDeniedError = 19,
|
||||||
SshSftpNoSuchPathError, SshSftpFileAlreadyExistsError, SshSftpWriteProtectError,
|
SshSftpFailureError = 20,
|
||||||
SshSftpNoMediaError,
|
SshSftpBadMessageError = 21,
|
||||||
|
SshSftpNoConnectionError = 22,
|
||||||
|
SshSftpConnectionLostError = 23,
|
||||||
|
SshSftpOpUnsupportedError = 24,
|
||||||
|
SshSftpInvalidHandleError = 25,
|
||||||
|
SshSftpNoSuchPathError = 26,
|
||||||
|
SshSftpFileAlreadyExistsError = 27,
|
||||||
|
SshSftpWriteProtectError = 28,
|
||||||
|
SshSftpNoMediaError = 29,
|
||||||
|
|
||||||
// Local errors
|
// Local errors
|
||||||
OpenVpnConfigMissing,
|
OpenVpnConfigMissing = 30,
|
||||||
OpenVpnManagementServerError,
|
OpenVpnManagementServerError = 31,
|
||||||
ConfigMissing,
|
ConfigMissing = 32,
|
||||||
|
|
||||||
// Distro errors
|
// Distro errors
|
||||||
OpenVpnExecutableMissing,
|
OpenVpnExecutableMissing = 33,
|
||||||
ShadowSocksExecutableMissing,
|
ShadowSocksExecutableMissing = 34,
|
||||||
CloakExecutableMissing,
|
CloakExecutableMissing = 35,
|
||||||
AmneziaServiceConnectionFailed,
|
AmneziaServiceConnectionFailed = 36,
|
||||||
ExecutableMissing,
|
ExecutableMissing = 37,
|
||||||
|
|
||||||
// VPN errors
|
// VPN errors
|
||||||
OpenVpnAdaptersInUseError,
|
OpenVpnAdaptersInUseError = 38,
|
||||||
OpenVpnUnknownError,
|
OpenVpnUnknownError = 39,
|
||||||
OpenVpnTapAdapterError,
|
OpenVpnTapAdapterError = 40,
|
||||||
AddressPoolError,
|
AddressPoolError = 41,
|
||||||
|
|
||||||
// 3rd party utils errors
|
// 3rd party utils errors
|
||||||
OpenSslFailed,
|
OpenSslFailed = 42,
|
||||||
ShadowSocksExecutableCrashed,
|
ShadowSocksExecutableCrashed = 43,
|
||||||
CloakExecutableCrashed,
|
CloakExecutableCrashed = 44,
|
||||||
|
|
||||||
// import and install errors
|
// import and install errors
|
||||||
ImportInvalidConfigError,
|
ImportInvalidConfigError = 45,
|
||||||
|
|
||||||
// Android errors
|
// Android errors
|
||||||
AndroidError
|
AndroidError = 46
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace amnezia
|
} // namespace amnezia
|
||||||
|
|
||||||
|
|
|
@ -2,70 +2,74 @@
|
||||||
|
|
||||||
using namespace amnezia;
|
using namespace amnezia;
|
||||||
|
|
||||||
QString errorString(ErrorCode code){
|
QString errorString(ErrorCode code) {
|
||||||
|
QString errorMessage;
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
||||||
// General error codes
|
// General error codes
|
||||||
case(NoError): return QObject::tr("No error");
|
case(NoError): errorMessage = QObject::tr("No error");
|
||||||
case(UnknownError): return QObject::tr("Unknown Error");
|
case(UnknownError): errorMessage = QObject::tr("Unknown Error");
|
||||||
case(NotImplementedError): return QObject::tr("Function not implemented");
|
case(NotImplementedError): errorMessage = QObject::tr("Function not implemented");
|
||||||
|
|
||||||
// Server errors
|
// Server errors
|
||||||
case(ServerCheckFailed): return QObject::tr("Server check failed");
|
case(ServerCheckFailed): errorMessage = QObject::tr("Server check failed");
|
||||||
case(ServerPortAlreadyAllocatedError): return QObject::tr("Server port already used. Check for another software");
|
case(ServerPortAlreadyAllocatedError): errorMessage = QObject::tr("Server port already used. Check for another software");
|
||||||
case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing");
|
case(ServerContainerMissingError): errorMessage = QObject::tr("Server error: Docker container missing");
|
||||||
case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed");
|
case(ServerDockerFailedError): errorMessage = QObject::tr("Server error: Docker failed");
|
||||||
case(ServerCancelInstallation): return QObject::tr("Installation canceled by user");
|
case(ServerCancelInstallation): errorMessage = QObject::tr("Installation canceled by user");
|
||||||
case(ServerUserNotInSudo): return QObject::tr("The user does not have permission to use sudo");
|
case(ServerUserNotInSudo): errorMessage = QObject::tr("The user does not have permission to use sudo");
|
||||||
|
|
||||||
// Libssh errors
|
// Libssh errors
|
||||||
case(SshRequestDeniedError): return QObject::tr("Ssh request was denied");
|
case(SshRequestDeniedError): errorMessage = QObject::tr("Ssh request was denied");
|
||||||
case(SshInterruptedError): return QObject::tr("Ssh request was interrupted");
|
case(SshInterruptedError): errorMessage = QObject::tr("Ssh request was interrupted");
|
||||||
case(SshInternalError): return QObject::tr("Ssh internal error");
|
case(SshInternalError): errorMessage = QObject::tr("Ssh internal error");
|
||||||
case(SshPrivateKeyError): return QObject::tr("Invalid private key or invalid passphrase entered");
|
case(SshPrivateKeyError): errorMessage = QObject::tr("Invalid private key or invalid passphrase entered");
|
||||||
case(SshPrivateKeyFormatError): return QObject::tr("The selected private key format is not supported, use openssh ED25519 key types or PEM key types");
|
case(SshPrivateKeyFormatError): errorMessage = QObject::tr("The selected private key format is not supported, use openssh ED25519 key types or PEM key types");
|
||||||
case(SshTimeoutError): return QObject::tr("Timeout connecting to server");
|
case(SshTimeoutError): errorMessage = QObject::tr("Timeout connecting to server");
|
||||||
|
|
||||||
// Libssh sftp errors
|
// Libssh sftp errors
|
||||||
case(SshSftpEofError): return QObject::tr("Sftp error: End-of-file encountered");
|
case(SshSftpEofError): errorMessage = QObject::tr("Sftp error: End-of-file encountered");
|
||||||
case(SshSftpNoSuchFileError): return QObject::tr("Sftp error: File does not exist");
|
case(SshSftpNoSuchFileError): errorMessage = QObject::tr("Sftp error: File does not exist");
|
||||||
case(SshSftpPermissionDeniedError): return QObject::tr("Sftp error: Permission denied");
|
case(SshSftpPermissionDeniedError): errorMessage = QObject::tr("Sftp error: Permission denied");
|
||||||
case(SshSftpFailureError): return QObject::tr("Sftp error: Generic failure");
|
case(SshSftpFailureError): errorMessage = QObject::tr("Sftp error: Generic failure");
|
||||||
case(SshSftpBadMessageError): return QObject::tr("Sftp error: Garbage received from server");
|
case(SshSftpBadMessageError): errorMessage = QObject::tr("Sftp error: Garbage received from server");
|
||||||
case(SshSftpNoConnectionError): return QObject::tr("Sftp error: No connection has been set up");
|
case(SshSftpNoConnectionError): errorMessage = QObject::tr("Sftp error: No connection has been set up");
|
||||||
case(SshSftpConnectionLostError): return QObject::tr("Sftp error: There was a connection, but we lost it");
|
case(SshSftpConnectionLostError): errorMessage = QObject::tr("Sftp error: There was a connection, but we lost it");
|
||||||
case(SshSftpOpUnsupportedError): return QObject::tr("Sftp error: Operation not supported by libssh yet");
|
case(SshSftpOpUnsupportedError): errorMessage = QObject::tr("Sftp error: Operation not supported by libssh yet");
|
||||||
case(SshSftpInvalidHandleError): return QObject::tr("Sftp error: Invalid file handle");
|
case(SshSftpInvalidHandleError): errorMessage = QObject::tr("Sftp error: Invalid file handle");
|
||||||
case(SshSftpNoSuchPathError): return QObject::tr("Sftp error: No such file or directory path exists");
|
case(SshSftpNoSuchPathError): errorMessage = QObject::tr("Sftp error: No such file or directory path exists");
|
||||||
case(SshSftpFileAlreadyExistsError): return QObject::tr("Sftp error: An attempt to create an already existing file or directory has been made");
|
case(SshSftpFileAlreadyExistsError): errorMessage = QObject::tr("Sftp error: An attempt to create an already existing file or directory has been made");
|
||||||
case(SshSftpWriteProtectError): return QObject::tr("Sftp error: Write-protected filesystem");
|
case(SshSftpWriteProtectError): errorMessage = QObject::tr("Sftp error: Write-protected filesystem");
|
||||||
case(SshSftpNoMediaError): return QObject::tr("Sftp error: No media was in remote drive");
|
case(SshSftpNoMediaError): errorMessage = QObject::tr("Sftp error: No media was in remote drive");
|
||||||
|
|
||||||
// Local errors
|
// Local errors
|
||||||
case (OpenVpnConfigMissing): return QObject::tr("OpenVPN config missing");
|
case (OpenVpnConfigMissing): errorMessage = QObject::tr("OpenVPN config missing");
|
||||||
case (OpenVpnManagementServerError): return QObject::tr("OpenVPN management server error");
|
case (OpenVpnManagementServerError): errorMessage = QObject::tr("OpenVPN management server error");
|
||||||
|
|
||||||
// Distro errors
|
// Distro errors
|
||||||
case (OpenVpnExecutableMissing): return QObject::tr("OpenVPN executable missing");
|
case (OpenVpnExecutableMissing): errorMessage = QObject::tr("OpenVPN executable missing");
|
||||||
case (ShadowSocksExecutableMissing): return QObject::tr("ShadowSocks (ss-local) executable missing");
|
case (ShadowSocksExecutableMissing): errorMessage = QObject::tr("ShadowSocks (ss-local) executable missing");
|
||||||
case (CloakExecutableMissing): return QObject::tr("Cloak (ck-client) executable missing");
|
case (CloakExecutableMissing): errorMessage = QObject::tr("Cloak (ck-client) executable missing");
|
||||||
case (AmneziaServiceConnectionFailed): return QObject::tr("Amnezia helper service error");
|
case (AmneziaServiceConnectionFailed): errorMessage = QObject::tr("Amnezia helper service error");
|
||||||
case (OpenSslFailed): return QObject::tr("OpenSSL failed");
|
case (OpenSslFailed): errorMessage = QObject::tr("OpenSSL failed");
|
||||||
|
|
||||||
// VPN errors
|
// VPN errors
|
||||||
case (OpenVpnAdaptersInUseError): return QObject::tr("Can't connect: another VPN connection is active");
|
case (OpenVpnAdaptersInUseError): errorMessage = QObject::tr("Can't connect: another VPN connection is active");
|
||||||
case (OpenVpnTapAdapterError): return QObject::tr("Can't setup OpenVPN TAP network adapter");
|
case (OpenVpnTapAdapterError): errorMessage = QObject::tr("Can't setup OpenVPN TAP network adapter");
|
||||||
case (AddressPoolError): return QObject::tr("VPN pool error: no available addresses");
|
case (AddressPoolError): errorMessage = QObject::tr("VPN pool error: no available addresses");
|
||||||
|
|
||||||
case (ImportInvalidConfigError): return QObject::tr("The config does not contain any containers and credentials for connecting to the server");
|
case (ImportInvalidConfigError): errorMessage = QObject::tr("The config does not contain any containers and credentials for connecting to the server");
|
||||||
|
|
||||||
// Android errors
|
// Android errors
|
||||||
case (AndroidError): return QObject::tr("VPN connection error");
|
case (AndroidError): errorMessage = QObject::tr("VPN connection error");
|
||||||
|
|
||||||
case(InternalError):
|
case(InternalError):
|
||||||
default:
|
default:
|
||||||
return QObject::tr("Internal error");
|
errorMessage = QObject::tr("Internal error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return errorMessage + QObject::tr("; ErrorCode: %1").arg(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const ErrorCode &e)
|
QDebug operator<<(QDebug debug, const ErrorCode &e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue