Skip to content

Commit

Permalink
Remove onInvalidInvocation(), clang-format formatting fixes
Browse files Browse the repository at this point in the history
WE2-145

Signed-off-by: Mart Somermaa <[email protected]>
  • Loading branch information
mrts committed Jun 21, 2024
1 parent 9f1e1f1 commit 2270c90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
15 changes: 1 addition & 14 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 10 additions & 10 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAbstractButton*>(&QButtonGroup::buttonClicked), this,
Expand Down Expand Up @@ -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("<b>Card reader not connected.</b> Please connect the card reader to "
"the computer."),
Expand All @@ -709,6 +710,7 @@ WebEidDialog::retriableErrorToTextTitleAndIcon(const RetriableError error) noexc
case RetriableError::PKCS11_TOKEN_NOT_PRESENT:
return {QT_TR_NOOP("<b>ID-card not found.</b> 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(
Expand All @@ -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(
Expand All @@ -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 "
Expand Down Expand Up @@ -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};
}
5 changes: 3 additions & 2 deletions tests/tests/changecertificatevaliduntil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <QDate>

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;
Expand Down Expand Up @@ -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));
}

0 comments on commit 2270c90

Please sign in to comment.