Skip to content

Commit

Permalink
feat(error-handling): make fatal error a standalone window
Browse files Browse the repository at this point in the history
Signed-off-by: Mart Somermaa <[email protected]>
  • Loading branch information
mrts committed Jun 11, 2021
1 parent ec45ae5 commit f3f20be
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,10 @@ void Controller::onCriticalFailure(const QString& error)
<< "fatal error:" << error;
writeResponseToStdOut(isInStdinMode, makeErrorObject(RESP_TECH_ERROR, error), commandType());

WebEidUI::createAndShowDialog(CommandType(CommandType::INSERT_CARD))->showFatalError();
// Dispose the UI.
window.reset();

WebEidUI::showFatalError();

exit();
}
Expand Down
3 changes: 2 additions & 1 deletion src/controller/ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class WebEidUI : public QDialog
// Factory function that creates and shows the dialog that implements this interface.
static ptr createAndShowDialog(const CommandType command);

virtual void showFatalError() {}
static void showFatalError();

virtual void showWaitingForCardPage(const CommandType commandType) = 0;

// getPin() is called from background threads and must be thread-safe.
Expand Down
8 changes: 4 additions & 4 deletions src/ui/dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ max-height: 20px;
#pinErrorLabel {
color: #F04E23;
}
#smartCardError {
#fatalError {
border: 1px solid rgba(240,78,35,0.1);
border-radius: 3px;
color: #F04E23;
Expand Down Expand Up @@ -282,7 +282,7 @@ color: #003168;
</layout>
</item>
<item>
<widget class="QWidget" name="smartCardError" native="true">
<widget class="QWidget" name="fatalError" native="true">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<property name="spacing">
<number>8</number>
Expand All @@ -300,14 +300,14 @@ color: #003168;
<number>10</number>
</property>
<item>
<widget class="QLabel" name="smartCardErrorIcon">
<widget class="QLabel" name="fatalErrorIcon">
<property name="pixmap">
<pixmap resource="web-eid-resources.qrc">:/images/fatal.svg</pixmap>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="smartCardErrorLabel">
<widget class="QLabel" name="fatalErrorLabel">
<property name="text">
<string>A fatal error occurred, check the logs for more details</string>
</property>
Expand Down
6 changes: 6 additions & 0 deletions src/ui/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType command)

return dialog;
}

void WebEidUI::showFatalError()
{
auto dialog = WebEidDialog {};
dialog.showFatalErrorPage();
}
6 changes: 3 additions & 3 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ WebEidDialog::WebEidDialog(QWidget* parent) : WebEidUI(parent), ui(new Private)
ui->pinInput->setAttribute(Qt::WA_MacShowFocusRect, false);
ui->waitingSpinner->load(QStringLiteral(":/images/wait.svg"));
ui->selectionGroup = new QButtonGroup(this);
ui->smartCardError->hide();
ui->fatalError->hide();

connect(ui->pageStack, &QStackedWidget::currentChanged, this, &WebEidDialog::resizeHeight);
connect(ui->selectionGroup, qOverload<QAbstractButton*>(&QButtonGroup::buttonClicked), this,
Expand Down Expand Up @@ -115,10 +115,10 @@ WebEidDialog::~WebEidDialog()
delete ui;
}

void WebEidDialog::showFatalError()
void WebEidDialog::showFatalErrorPage()
{
ui->messagePageTitleLabel->setText(tr("Fatal error"));
ui->smartCardError->show();
ui->fatalError->show();
ui->connectCardLabel->hide();
ui->cardChipIcon->hide();
ui->helpButton->show();
Expand Down
3 changes: 2 additions & 1 deletion src/ui/webeiddialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class WebEidDialog : public WebEidUI
explicit WebEidDialog(QWidget* parent = nullptr);
~WebEidDialog() override;

void showFatalError() override;
void showWaitingForCardPage(const CommandType commandType) override;
QString getPin() override;

void showFatalErrorPage();

public: // slots
void onSmartCardStatusUpdate(const RetriableError status) override;
void onMultipleCertificatesReady(
Expand Down
2 changes: 2 additions & 0 deletions tests/mock-ui/mock-ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ WebEidUI::ptr WebEidUI::createAndShowDialog(const CommandType)
{
return std::make_unique<MockUI>();
}

void WebEidUI::showFatalError() {}

0 comments on commit f3f20be

Please sign in to comment.