Merge pull request #480 from amnezia-vpn/feature/error-code-output

added error code output
This commit is contained in:
pokamest 2024-02-01 05:05:36 -08:00 committed by GitHub
commit cdf46c968a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 120 additions and 101 deletions

View file

@ -4,77 +4,92 @@
#include <QMetaEnum> #include <QMetaEnum>
#include <QObject> #include <QObject>
namespace amnezia { namespace amnezia
constexpr const qint16 qrMagicCode = 1984;
struct ServerCredentials
{ {
QString hostName;
QString userName;
QString secretData;
int port = 22;
bool isValid() const { return !hostName.isEmpty() && !userName.isEmpty() && !secretData.isEmpty() && port > 0; } constexpr const qint16 qrMagicCode = 1984;
};
enum ErrorCode struct ServerCredentials
{ {
// General error codes QString hostName;
NoError = 0, QString userName;
UnknownError, QString secretData;
InternalError, int port = 22;
NotImplementedError,
// Server errors bool isValid() const
ServerCheckFailed, {
ServerPortAlreadyAllocatedError, return !hostName.isEmpty() && !userName.isEmpty() && !secretData.isEmpty() && port > 0;
ServerContainerMissingError, }
ServerDockerFailedError, };
ServerCancelInstallation,
ServerUserNotInSudo,
ServerPacketManagerError,
// Ssh connection errors enum ErrorCode {
SshRequestDeniedError, SshInterruptedError, SshInternalError, // General error codes
SshPrivateKeyError, SshPrivateKeyFormatError, SshTimeoutError, NoError = 0,
UnknownError = 100,
InternalError = 101,
NotImplementedError = 102,
// Ssh sftp errors // Server errors
SshSftpEofError, SshSftpNoSuchFileError, SshSftpPermissionDeniedError, ServerCheckFailed = 200,
SshSftpFailureError, SshSftpBadMessageError, SshSftpNoConnectionError, ServerPortAlreadyAllocatedError = 201,
SshSftpConnectionLostError, SshSftpOpUnsupportedError, SshSftpInvalidHandleError, ServerContainerMissingError = 202,
SshSftpNoSuchPathError, SshSftpFileAlreadyExistsError, SshSftpWriteProtectError, ServerDockerFailedError = 203,
SshSftpNoMediaError, ServerCancelInstallation = 204,
ServerUserNotInSudo = 205,
ServerPacketManagerError = 206,
// Local errors // Ssh connection errors
OpenVpnConfigMissing, SshRequestDeniedError = 300,
OpenVpnManagementServerError, SshInterruptedError = 301,
ConfigMissing, SshInternalError = 302,
SshPrivateKeyError = 303,
SshPrivateKeyFormatError = 304,
SshTimeoutError = 305,
// Distro errors // Ssh sftp errors
OpenVpnExecutableMissing, SshSftpEofError = 400,
ShadowSocksExecutableMissing, SshSftpNoSuchFileError = 401,
CloakExecutableMissing, SshSftpPermissionDeniedError = 402,
AmneziaServiceConnectionFailed, SshSftpFailureError = 403,
ExecutableMissing, SshSftpBadMessageError = 404,
SshSftpNoConnectionError = 405,
SshSftpConnectionLostError = 406,
SshSftpOpUnsupportedError = 407,
SshSftpInvalidHandleError = 408,
SshSftpNoSuchPathError = 409,
SshSftpFileAlreadyExistsError = 410,
SshSftpWriteProtectError = 411,
SshSftpNoMediaError = 412,
// VPN errors // Local errors
OpenVpnAdaptersInUseError, OpenVpnConfigMissing = 500,
OpenVpnUnknownError, OpenVpnManagementServerError = 501,
OpenVpnTapAdapterError, ConfigMissing = 502,
AddressPoolError,
// 3rd party utils errors // Distro errors
OpenSslFailed, OpenVpnExecutableMissing = 600,
ShadowSocksExecutableCrashed, ShadowSocksExecutableMissing = 601,
CloakExecutableCrashed, CloakExecutableMissing = 602,
AmneziaServiceConnectionFailed = 603,
ExecutableMissing = 604,
// import and install errors // VPN errors
ImportInvalidConfigError, OpenVpnAdaptersInUseError = 700,
OpenVpnUnknownError = 701,
OpenVpnTapAdapterError = 702,
AddressPoolError = 703,
// Android errors // 3rd party utils errors
AndroidError OpenSslFailed = 800,
}; ShadowSocksExecutableCrashed = 801,
CloakExecutableCrashed = 802,
// import and install errors
ImportInvalidConfigError = 900,
// Android errors
AndroidError = 1000
};
} // namespace amnezia } // namespace amnezia

View file

@ -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"); break;
case(UnknownError): return QObject::tr("Unknown Error"); case(UnknownError): errorMessage = QObject::tr("Unknown Error"); break;
case(NotImplementedError): return QObject::tr("Function not implemented"); case(NotImplementedError): errorMessage = QObject::tr("Function not implemented"); break;
// Server errors // Server errors
case(ServerCheckFailed): return QObject::tr("Server check failed"); case(ServerCheckFailed): errorMessage = QObject::tr("Server check failed"); break;
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"); break;
case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing"); case(ServerContainerMissingError): errorMessage = QObject::tr("Server error: Docker container missing"); break;
case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed"); case(ServerDockerFailedError): errorMessage = QObject::tr("Server error: Docker failed"); break;
case(ServerCancelInstallation): return QObject::tr("Installation canceled by user"); case(ServerCancelInstallation): errorMessage = QObject::tr("Installation canceled by user"); break;
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"); break;
// Libssh errors // Libssh errors
case(SshRequestDeniedError): return QObject::tr("Ssh request was denied"); case(SshRequestDeniedError): errorMessage = QObject::tr("Ssh request was denied"); break;
case(SshInterruptedError): return QObject::tr("Ssh request was interrupted"); case(SshInterruptedError): errorMessage = QObject::tr("Ssh request was interrupted"); break;
case(SshInternalError): return QObject::tr("Ssh internal error"); case(SshInternalError): errorMessage = QObject::tr("Ssh internal error"); break;
case(SshPrivateKeyError): return QObject::tr("Invalid private key or invalid passphrase entered"); case(SshPrivateKeyError): errorMessage = QObject::tr("Invalid private key or invalid passphrase entered"); break;
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"); break;
case(SshTimeoutError): return QObject::tr("Timeout connecting to server"); case(SshTimeoutError): errorMessage = QObject::tr("Timeout connecting to server"); break;
// 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"); break;
case(SshSftpNoSuchFileError): return QObject::tr("Sftp error: File does not exist"); case(SshSftpNoSuchFileError): errorMessage = QObject::tr("Sftp error: File does not exist"); break;
case(SshSftpPermissionDeniedError): return QObject::tr("Sftp error: Permission denied"); case(SshSftpPermissionDeniedError): errorMessage = QObject::tr("Sftp error: Permission denied"); break;
case(SshSftpFailureError): return QObject::tr("Sftp error: Generic failure"); case(SshSftpFailureError): errorMessage = QObject::tr("Sftp error: Generic failure"); break;
case(SshSftpBadMessageError): return QObject::tr("Sftp error: Garbage received from server"); case(SshSftpBadMessageError): errorMessage = QObject::tr("Sftp error: Garbage received from server"); break;
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"); break;
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"); break;
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"); break;
case(SshSftpInvalidHandleError): return QObject::tr("Sftp error: Invalid file handle"); case(SshSftpInvalidHandleError): errorMessage = QObject::tr("Sftp error: Invalid file handle"); break;
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"); break;
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"); break;
case(SshSftpWriteProtectError): return QObject::tr("Sftp error: Write-protected filesystem"); case(SshSftpWriteProtectError): errorMessage = QObject::tr("Sftp error: Write-protected filesystem"); break;
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"); break;
// Local errors // Local errors
case (OpenVpnConfigMissing): return QObject::tr("OpenVPN config missing"); case (OpenVpnConfigMissing): errorMessage = QObject::tr("OpenVPN config missing"); break;
case (OpenVpnManagementServerError): return QObject::tr("OpenVPN management server error"); case (OpenVpnManagementServerError): errorMessage = QObject::tr("OpenVPN management server error"); break;
// Distro errors // Distro errors
case (OpenVpnExecutableMissing): return QObject::tr("OpenVPN executable missing"); case (OpenVpnExecutableMissing): errorMessage = QObject::tr("OpenVPN executable missing"); break;
case (ShadowSocksExecutableMissing): return QObject::tr("ShadowSocks (ss-local) executable missing"); case (ShadowSocksExecutableMissing): errorMessage = QObject::tr("ShadowSocks (ss-local) executable missing"); break;
case (CloakExecutableMissing): return QObject::tr("Cloak (ck-client) executable missing"); case (CloakExecutableMissing): errorMessage = QObject::tr("Cloak (ck-client) executable missing"); break;
case (AmneziaServiceConnectionFailed): return QObject::tr("Amnezia helper service error"); case (AmneziaServiceConnectionFailed): errorMessage = QObject::tr("Amnezia helper service error"); break;
case (OpenSslFailed): return QObject::tr("OpenSSL failed"); case (OpenSslFailed): errorMessage = QObject::tr("OpenSSL failed"); break;
// 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"); break;
case (OpenVpnTapAdapterError): return QObject::tr("Can't setup OpenVPN TAP network adapter"); case (OpenVpnTapAdapterError): errorMessage = QObject::tr("Can't setup OpenVPN TAP network adapter"); break;
case (AddressPoolError): return QObject::tr("VPN pool error: no available addresses"); case (AddressPoolError): errorMessage = QObject::tr("VPN pool error: no available addresses"); break;
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"); break;
// Android errors // Android errors
case (AndroidError): return QObject::tr("VPN connection error"); case (AndroidError): errorMessage = QObject::tr("VPN connection error"); break;
case(InternalError): case(InternalError):
default: default:
return QObject::tr("Internal error"); errorMessage = QObject::tr("Internal error"); break;
} }
return QObject::tr("ErrorCode: %1. ").arg(code) + errorMessage;
} }
QDebug operator<<(QDebug debug, const ErrorCode &e) QDebug operator<<(QDebug debug, const ErrorCode &e)