From 2270c90986560c81c0defcd55e6fbd0fccdb40d9 Mon Sep 17 00:00:00 2001 From: Mart Somermaa Date: Fri, 21 Jun 2024 19:12:24 +0300 Subject: [PATCH] Remove onInvalidInvocation(), clang-format formatting fixes WE2-145 Signed-off-by: Mart Somermaa --- src/controller/controller.cpp | 15 +-------------- src/controller/controller.hpp | 2 -- src/ui/webeiddialog.cpp | 20 ++++++++++---------- tests/tests/changecertificatevaliduntil.hpp | 5 +++-- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 8be95970..5894e103 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -40,7 +40,6 @@ namespace { const QString RESP_TECH_ERROR = QStringLiteral("ERR_WEBEID_NATIVE_FATAL"); -const QString RESP_INVALID_INVOCATION = QStringLiteral("ERR_WEBEID_INVALID_INVOCATION"); const QString RESP_USER_CANCEL = QStringLiteral("ERR_WEBEID_USER_CANCELLED"); QVariantMap makeErrorObject(const QString& errorCode, const QString& errorMessage) @@ -101,8 +100,7 @@ void Controller::run() commandHandler = getCommandHandler(*command); startCommandExecution(); - } catch (const std::invalid_argument& error) { - onInvalidInvocation(error.what()); + } catch (const std::exception& error) { onCriticalFailure(error.what()); } @@ -362,17 +360,6 @@ void Controller::onCriticalFailure(const QString& error) exit(); } -void Controller::onInvalidInvocation(const QString& error) -{ - qCritical() << "Invalid arguments to command" << std::string(commandType()) - << "reason:" << error; - _result = makeErrorObject(RESP_INVALID_INVOCATION, error); - writeResponseToStdOut(isInStdinMode, _result, commandType()); - disposeUI(); - WebEidUI::showFatalError(); - exit(); -} - void Controller::exit() { if (window) { diff --git a/src/controller/controller.hpp b/src/controller/controller.hpp index d0001ea9..e4af4828 100644 --- a/src/controller/controller.hpp +++ b/src/controller/controller.hpp @@ -70,8 +70,6 @@ class Controller : public QObject // Failure handler, reports the error and quits the application. void onCriticalFailure(const QString& error); - // Invalid arguments, we keep it spearate to distinguish it from technical errors - void onInvalidInvocation(const QString& error); private: void startCommandExecution(); diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index 7c09fe72..93bcfa14 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -159,7 +159,7 @@ WebEidDialog::WebEidDialog(QWidget* parent) : WebEidUI(parent), ui(new Private) ui->fatalHelp->hide(); ui->selectAnotherCertificate->hide(); - connect(ui->pageStack, &QStackedWidget::currentChanged, this, [this]{ + connect(ui->pageStack, &QStackedWidget::currentChanged, this, [this] { ui->pageStack->setFixedHeight(ui->pageStack->currentWidget()->sizeHint().height()); }); connect(ui->selectionGroup, qOverload(&QButtonGroup::buttonClicked), this, @@ -700,6 +700,7 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc QT_TR_NOOP("The smart card service required to use the ID-card is not running. Please " "start the smart card service and try again."), QT_TR_NOOP("Launch the Smart Card service"), "cardreader"_L1}; + case RetriableError::NO_SMART_CARD_READERS_FOUND: return {QT_TR_NOOP("Card reader not connected. Please connect the card reader to " "the computer."), @@ -709,6 +710,7 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc case RetriableError::PKCS11_TOKEN_NOT_PRESENT: return {QT_TR_NOOP("ID-card not found. Please insert the ID-card into the reader."), QT_TR_NOOP("Insert the ID-card"), "no-id-card"_L1}; + case RetriableError::SMART_CARD_WAS_REMOVED: case RetriableError::PKCS11_TOKEN_REMOVED: return {QT_TR_NOOP( @@ -722,6 +724,7 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc "Operation failed. Make sure that the ID-card and the card reader are connected " "correctly."), QT_TR_NOOP("Check the ID-card and the reader connection"), "no-id-card"_L1}; + case RetriableError::FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER: return { QT_TR_NOOP( @@ -737,17 +740,13 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc QT_TR_NOOP("Operation not supported"), "no-id-card"_L1}; case RetriableError::SMART_CARD_COMMAND_ERROR: - return { - QT_TR_NOOP( - "Error communicating with the card."), - QT_TR_NOOP("Operation failed"), "no-id-card"_L1}; + return {QT_TR_NOOP("Error communicating with the card."), QT_TR_NOOP("Operation failed"), + "no-id-card"_L1}; case RetriableError::PKCS11_ERROR: - return { - QT_TR_NOOP( - "Card driver error. Please try again."), - QT_TR_NOOP("Card driver error"), "no-id-card"_L1}; - + return {QT_TR_NOOP("Card driver error. Please try again."), QT_TR_NOOP("Card driver error"), + "no-id-card"_L1}; + case RetriableError::SCARD_ERROR: return {QT_TR_NOOP( "An error occurred in the Smart Card service required to use the ID-card. Make " @@ -780,5 +779,6 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc case RetriableError::UNKNOWN_ERROR: return {QT_TR_NOOP("Unknown error"), QT_TR_NOOP("Unknown error"), "no-id-card"_L1}; } + return {QT_TR_NOOP("Unknown error"), QT_TR_NOOP("Unknown error"), "no-id-card"_L1}; } diff --git a/tests/tests/changecertificatevaliduntil.hpp b/tests/tests/changecertificatevaliduntil.hpp index 3b8e76cc..7c4dfcf8 100644 --- a/tests/tests/changecertificatevaliduntil.hpp +++ b/tests/tests/changecertificatevaliduntil.hpp @@ -28,7 +28,7 @@ #include inline PcscMock::byte_vector::iterator findUTCDateTime(PcscMock::byte_vector::iterator first, - PcscMock::byte_vector::iterator last) + PcscMock::byte_vector::iterator last) { constexpr unsigned char UTC_DATETIME_TAG = 0x17; constexpr unsigned char LENGTH_TAG = 0x0d; @@ -93,5 +93,6 @@ inline PcscMock::ApduScript replaceCertValidUntilTo2010(const PcscMock::ApduScri inline PcscMock::ApduScript replaceCertValidUntilToNextYear(const PcscMock::ApduScript& script) { // UTCDateTime needs 2-digit year since 2000, add +1 for next year - return replaceCertValidUntilYear(script, 4, std::to_string(QDate::currentDate().year() - 2000 + 1)); + return replaceCertValidUntilYear(script, 4, + std::to_string(QDate::currentDate().year() - 2000 + 1)); }