mirror of
https://github.com/QRouland/UTPass.git
synced 2025-03-20 23:44:50 +00:00
Improve Lib Pass Error Messages
This commit is contained in:
parent
bdb2d58ac4
commit
dc2c35ca9b
@ -6,25 +6,66 @@ extern "C" {
|
|||||||
#include "rnp/rnp_err.h"
|
#include "rnp/rnp_err.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ErrorCodeShow {
|
enum class ErrorCodeShow {
|
||||||
UnexceptedError= 1,
|
Success= 0,
|
||||||
|
UnexceptedError,
|
||||||
BadPassphrase,
|
BadPassphrase,
|
||||||
NoKeyFound,
|
NoKeyFound,
|
||||||
DecryptFailed
|
DecryptFailed
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorCodeShow rnpErrorToErrorCodeShow(int rnpErrorCode) {
|
int rnpErrorToErrorCodeShow(int rnpErrorCode) {
|
||||||
switch (rnpErrorCode) {
|
switch (rnpErrorCode) {
|
||||||
|
case RNP_SUCCESS:
|
||||||
|
return static_cast<int>(ErrorCodeShow::Success);
|
||||||
case RNP_ERROR_BAD_PASSWORD:
|
case RNP_ERROR_BAD_PASSWORD:
|
||||||
return BadPassphrase;
|
return static_cast<int>(ErrorCodeShow::BadPassphrase);
|
||||||
case RNP_ERROR_KEY_NOT_FOUND:
|
case RNP_ERROR_KEY_NOT_FOUND:
|
||||||
case RNP_ERROR_NO_SUITABLE_KEY:
|
case RNP_ERROR_NO_SUITABLE_KEY:
|
||||||
return NoKeyFound;
|
return static_cast<int>(ErrorCodeShow::NoKeyFound);
|
||||||
case RNP_ERROR_DECRYPT_FAILED:
|
case RNP_ERROR_DECRYPT_FAILED:
|
||||||
return DecryptFailed;
|
return static_cast<int>(ErrorCodeShow::DecryptFailed);
|
||||||
default:
|
default:
|
||||||
return UnexceptedError;
|
return static_cast<int>(ErrorCodeShow::UnexceptedError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ErrorCodeImportKeyFile {
|
||||||
|
Success= 0,
|
||||||
|
UnexceptedError,
|
||||||
|
BadFormat,
|
||||||
|
};
|
||||||
|
|
||||||
|
int rnpErrorToErrorCodeImportKeyFile(int rnpErrorCode) {
|
||||||
|
switch (rnpErrorCode) {
|
||||||
|
case RNP_SUCCESS:
|
||||||
|
return static_cast<int>(ErrorCodeShow::Success);
|
||||||
|
case RNP_ERROR_BAD_FORMAT:
|
||||||
|
return static_cast<int>(ErrorCodeImportKeyFile::BadFormat);
|
||||||
|
default:
|
||||||
|
return static_cast<int>(ErrorCodeImportKeyFile::UnexceptedError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
enum class ErrorCodeUnexvepted {
|
||||||
|
Success= 0,
|
||||||
|
UnexceptedError,
|
||||||
|
};
|
||||||
|
|
||||||
|
int rnpErrorToErrorCodeGeneric(int rnpErrorCode) {
|
||||||
|
switch (rnpErrorCode) {
|
||||||
|
case RNP_SUCCESS:
|
||||||
|
return static_cast<int>(ErrorCodeShow::Success);
|
||||||
|
default:
|
||||||
|
return static_cast<int>(ErrorCodeImportKeyFile::UnexceptedError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class ErrorCode
|
||||||
|
{
|
||||||
|
Success= 0,
|
||||||
|
Error,
|
||||||
|
};
|
||||||
|
|
||||||
#endif // ERROR_H
|
#endif // ERROR_H
|
||||||
|
@ -42,29 +42,6 @@ void ImportKeyJob::run()
|
|||||||
|
|
||||||
// Save resulting keyring
|
// Save resulting keyring
|
||||||
this->saveFullKeyring();
|
this->saveFullKeyring();
|
||||||
// rnp_output_t output = NULL;
|
|
||||||
// qDebug() << "[ImportKeyJob] Writing pubring to " << this->pubringPath();
|
|
||||||
// ret = rnp_output_to_file(&output, this->pubringPath().toLocal8Bit().constData(), RNP_OUTPUT_FILE_OVERWRITE);
|
|
||||||
// if (ret == RNP_SUCCESS) {
|
|
||||||
// qDebug() << "[ImportKeyJob] Saving key pubring ";
|
|
||||||
// ret = rnp_save_keys(this->m_ffi, RNP_KEYSTORE_GPG, output, RNP_LOAD_SAVE_PUBLIC_KEYS);
|
|
||||||
|
|
||||||
// }
|
|
||||||
// if (ret == RNP_SUCCESS) {
|
|
||||||
// ret = rnp_output_finish(output);
|
|
||||||
// }
|
|
||||||
// rnp_output_destroy(output);
|
|
||||||
// terminateOnError(ret);
|
|
||||||
|
|
||||||
// qDebug() << "[ImportKeyJob] Writing secring to " << this->secringPath();
|
|
||||||
// ret = rnp_output_to_file(&output, this->secringPath().toLocal8Bit().constData(), RNP_OUTPUT_FILE_OVERWRITE);
|
|
||||||
// if (ret == RNP_SUCCESS) {
|
|
||||||
// qDebug() << "[ImportKeyJob] Saving key secring ";
|
|
||||||
// ret = rnp_save_keys(this->m_ffi, RNP_KEYSTORE_GPG, output, RNP_LOAD_SAVE_SECRET_KEYS);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// rnp_output_destroy(output);
|
|
||||||
// terminateOnError(ret);
|
|
||||||
|
|
||||||
// Emit result
|
// Emit result
|
||||||
emit resultSuccess();
|
emit resultSuccess();
|
||||||
|
@ -140,7 +140,7 @@ void Pass::slotDeletePasswordStoreResult(bool err)
|
|||||||
{
|
{
|
||||||
if (err) {
|
if (err) {
|
||||||
qInfo() << "[Pass] Delete Password Store Failed";
|
qInfo() << "[Pass] Delete Password Store Failed";
|
||||||
emit deletePasswordStoreFailed("failed to delete password store");
|
emit deletePasswordStoreFailed(static_cast<int>(ErrorCodeRmFile::Error), "Failed to delete password store");
|
||||||
} else {
|
} else {
|
||||||
qInfo() << "[Pass] Delete Password Store Succeed";
|
qInfo() << "[Pass] Delete Password Store Succeed";
|
||||||
this->initPasswordStore(); // reinit an empty password-store
|
this->initPasswordStore(); // reinit an empty password-store
|
||||||
@ -168,7 +168,7 @@ bool Pass::deleteGPGKey(PassKeyModel* key)
|
|||||||
void Pass::slotDeleteGPGKeyError(rnp_result_t err)
|
void Pass::slotDeleteGPGKeyError(rnp_result_t err)
|
||||||
{
|
{
|
||||||
qInfo() << "[Pass] Delete GPG key Failed";
|
qInfo() << "[Pass] Delete GPG key Failed";
|
||||||
emit deleteGPGKeyFailed(rnp_result_to_string(err));
|
emit deleteGPGKeyFailed(rnpErrorToErrorCodeGeneric(err), rnp_result_to_string(err));
|
||||||
this->m_sem->release(1);
|
this->m_sem->release(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ bool Pass::importGPGKey(QUrl url)
|
|||||||
void Pass::slotImportGPGKeyError(rnp_result_t err)
|
void Pass::slotImportGPGKeyError(rnp_result_t err)
|
||||||
{
|
{
|
||||||
qInfo() << "[Pass] Import GPG Key Failed";
|
qInfo() << "[Pass] Import GPG Key Failed";
|
||||||
emit importGPGKeyFailed(rnp_result_to_string(err));
|
emit importGPGKeyFailed(rnpErrorToErrorCodeImportKeyFile(err), rnp_result_to_string(err));
|
||||||
this->m_sem->release(1);
|
this->m_sem->release(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ void Pass::slotGetAllGPGKeysError(rnp_result_t err)
|
|||||||
{
|
{
|
||||||
qInfo() << "[Pass] Get all GPG Keys Failed";
|
qInfo() << "[Pass] Get all GPG Keys Failed";
|
||||||
this->m_keyring_model = nullptr;
|
this->m_keyring_model = nullptr;
|
||||||
emit getAllGPGKeysFailed(rnp_result_to_string(err));
|
emit getAllGPGKeysFailed(rnpErrorToErrorCodeGeneric(err), rnp_result_to_string(err));
|
||||||
this->m_sem->release(1);
|
this->m_sem->release(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ signals:
|
|||||||
* @brief Emitted when a GPG key deletion fails.
|
* @brief Emitted when a GPG key deletion fails.
|
||||||
* @param message The error message describing the failure.
|
* @param message The error message describing the failure.
|
||||||
*/
|
*/
|
||||||
void deleteGPGKeyFailed(QString message);
|
void deleteGPGKeyFailed(int err, QString message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when a GPG key is successfully imported.
|
* @brief Emitted when a GPG key is successfully imported.
|
||||||
@ -89,7 +89,7 @@ signals:
|
|||||||
* @brief Emitted when a GPG key import fails.
|
* @brief Emitted when a GPG key import fails.
|
||||||
* @param message The error message describing the failure.
|
* @param message The error message describing the failure.
|
||||||
*/
|
*/
|
||||||
void importGPGKeyFailed(QString message);
|
void importGPGKeyFailed(int err, QString message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Emitted when all GPG keys are successfully retrieved.
|
* @brief Emitted when all GPG keys are successfully retrieved.
|
||||||
@ -101,7 +101,7 @@ signals:
|
|||||||
* @brief Emitted when retrieving GPG keys fails.
|
* @brief Emitted when retrieving GPG keys fails.
|
||||||
* @param message The error message describing the failure.
|
* @param message The error message describing the failure.
|
||||||
*/
|
*/
|
||||||
void getAllGPGKeysFailed(QString message);
|
void getAllGPGKeysFailed(int err, QString message);
|
||||||
|
|
||||||
// Pass-related signals
|
// Pass-related signals
|
||||||
/**
|
/**
|
||||||
@ -142,7 +142,7 @@ signals:
|
|||||||
* @brief Emitted when deleting the password store fails.
|
* @brief Emitted when deleting the password store fails.
|
||||||
* @param message The error message describing the failure.
|
* @param message The error message describing the failure.
|
||||||
*/
|
*/
|
||||||
void deletePasswordStoreFailed(QString message);
|
void deletePasswordStoreFailed(int err, QString message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_password_store; /**< The path to the password store. */
|
QString m_password_store; /**< The path to the password store. */
|
||||||
|
@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: utpass.qrouland\n"
|
"Project-Id-Version: utpass.qrouland\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2025-03-12 15:16+0100\n"
|
"POT-Creation-Date: 2025-03-12 16:37+0100\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@ -71,8 +71,8 @@ msgstr ""
|
|||||||
msgid "Import failed !"
|
msgid "Import failed !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/components/ImportFile.qml:20
|
#: ../qml/components/ImportFile.qml:21
|
||||||
msgid "File Import"
|
msgid "File Imported"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/dialogs/ErrorDialog.qml:13
|
#: ../qml/dialogs/ErrorDialog.qml:13
|
||||||
@ -145,27 +145,31 @@ msgstr ""
|
|||||||
msgid "No valid key found"
|
msgid "No valid key found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:92
|
#: ../qml/pages/PasswordList.qml:64
|
||||||
|
msgid "Decryption failed"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: ../qml/pages/PasswordList.qml:98
|
||||||
msgid "No password found"
|
msgid "No password found"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:105
|
#: ../qml/pages/PasswordList.qml:111
|
||||||
msgid "You can import a password store by cloning or"
|
msgid "You can import a password store by cloning or"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:112
|
#: ../qml/pages/PasswordList.qml:118
|
||||||
msgid "importing a password store zip in the settings"
|
msgid "importing a password store zip in the settings"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:189
|
#: ../qml/pages/PasswordList.qml:195
|
||||||
msgid "Decryption failed !"
|
msgid "Decryption failed !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:213
|
#: ../qml/pages/PasswordList.qml:219
|
||||||
msgid "Back"
|
msgid "Back"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/PasswordList.qml:220 ../qml/pages/headers/MainHeader.qml:14
|
#: ../qml/pages/PasswordList.qml:226 ../qml/pages/headers/MainHeader.qml:14
|
||||||
#: ../qml/pages/headers/StackHeader.qml:9 UTPass.desktop.in.h:1
|
#: ../qml/pages/headers/StackHeader.qml:9 UTPass.desktop.in.h:1
|
||||||
msgid "UTPass"
|
msgid "UTPass"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
@ -223,18 +227,22 @@ msgstr ""
|
|||||||
msgid "Git Clone Import"
|
msgid "Git Clone Import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/ImportKeyFile.qml:8
|
#: ../qml/pages/settings/ImportKeyFile.qml:7
|
||||||
msgid "GPG Key Import"
|
msgid "GPG Key Import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/ImportKeyFile.qml:9
|
#: ../qml/pages/settings/ImportKeyFile.qml:8
|
||||||
msgid "Key successfully imported !"
|
msgid "Key successfully imported !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/ImportKeyFile.qml:10
|
#: ../qml/pages/settings/ImportKeyFile.qml:9
|
||||||
msgid "Key import failed !"
|
msgid "Key import failed !"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
#: ../qml/pages/settings/ImportKeyFile.qml:33
|
||||||
|
msgid "The file is not in a valid key format"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
#: ../qml/pages/settings/ImportSSHkey.qml:10
|
#: ../qml/pages/settings/ImportSSHkey.qml:10
|
||||||
msgid "SSH Key Import"
|
msgid "SSH Key Import"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -17,7 +17,8 @@ Page {
|
|||||||
|
|
||||||
property string headerTitle : i18n.tr("Import succeeded !")
|
property string headerTitle : i18n.tr("Import succeeded !")
|
||||||
property string dialogErrorTxt : i18n.tr("Import failed !")
|
property string dialogErrorTxt : i18n.tr("Import failed !")
|
||||||
property string dialogSuccessTxt : i18n.tr("File Import")
|
property string dialogErrorDescriptionTxt : null
|
||||||
|
property string dialogSuccessTxt : i18n.tr("File Imported")
|
||||||
|
|
||||||
ContentPeerPicker {
|
ContentPeerPicker {
|
||||||
id: contentPicker
|
id: contentPicker
|
||||||
@ -46,6 +47,7 @@ Page {
|
|||||||
|
|
||||||
ErrorDialog {
|
ErrorDialog {
|
||||||
textError: importKeyFilePage.dialogErrorTxt
|
textError: importKeyFilePage.dialogErrorTxt
|
||||||
|
textErrorDescription: importKeyFilePage.dialogErrorDescriptionTxt
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import "../../components"
|
|||||||
import Pass 1.0
|
import Pass 1.0
|
||||||
|
|
||||||
ImportFile {
|
ImportFile {
|
||||||
|
|
||||||
id: importKeyFilePage
|
id: importKeyFilePage
|
||||||
|
|
||||||
headerTitle: i18n.tr("GPG Key Import")
|
headerTitle: i18n.tr("GPG Key Import")
|
||||||
@ -23,9 +22,21 @@ ImportFile {
|
|||||||
importKeyFilePage.activeTransfer = null;
|
importKeyFilePage.activeTransfer = null;
|
||||||
PopupUtils.open(importKeyFilePage.dialogImportKeyPageSucess);
|
PopupUtils.open(importKeyFilePage.dialogImportKeyPageSucess);
|
||||||
});
|
});
|
||||||
Pass.importGPGKeyFailed.connect(function(message) {
|
Pass.importGPGKeyFailed.connect(function(err, message) {
|
||||||
Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url);
|
Utils.rmFile(importKeyFilePage.activeTransfer.items[0].url);
|
||||||
importKeyFilePage.activeTransfer = null;
|
importKeyFilePage.activeTransfer = null;
|
||||||
|
switch (code) {
|
||||||
|
case 1: // UnexceptedError -> use the default (not translate) rnp error
|
||||||
|
__text_error_description = message;
|
||||||
|
break;
|
||||||
|
case 2: // BadFormat
|
||||||
|
__text_error_description = i18n.tr("The file is not in a valid key format");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn("Unhandled error code");
|
||||||
|
__text_error_description = message;
|
||||||
|
break;
|
||||||
|
}
|
||||||
PopupUtils.open(importKeyFilePage.dialogImportKeyPageError);
|
PopupUtils.open(importKeyFilePage.dialogImportKeyPageError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user