Commit 1e2988d7 authored by Ivan Čukić's avatar Ivan Čukić 👁

Show command output on unknown failure

Summary:
If the error is unknown (all errors in encfs), show the 'details...' button
which shows the command line output to the user when activated.

BUG:412779

Reviewers: #plasma, davidedmundson, ngraham, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28099
parent 12e82f6c
......@@ -9,6 +9,8 @@ _tests
.ycm_extra_conf.py
.ycm_extra_conf.pyc
.clang_complete
.clangd
.ccls-cache
kactivities.kdev4
compile_commands.json
/apidocs
......
......@@ -193,7 +193,8 @@ FutureResult<> CryFsBackend::mount(const Device &device,
// otherwise just report that we failed
Result<>::error(Error::CommandError,
i18n("Unable to perform the operation (error code %1).", QString::number((int)exitCode)));
i18n("Unable to perform the operation (error code %1).", QString::number((int)exitCode)),
out, err);
});
......
......@@ -22,9 +22,11 @@
namespace PlasmaVault {
Error::Error(Code code, const QString &message)
Error::Error(Code code, const QString &message, const QString &out, const QString &err)
: m_code(code)
, m_message(message)
, m_out(out)
, m_err(err)
{
}
......@@ -38,5 +40,15 @@ QString Error::message() const
return m_message;
}
QString Error::out() const
{
return m_out;
}
QString Error::err() const
{
return m_err;
}
} // namespace PlasmaVault
......@@ -35,17 +35,22 @@ public:
DeviceError,
BackendError,
CommandError,
DeletionError
DeletionError,
UnknownError
};
Error(Code code, const QString &message = QString());
Error(Code code = UnknownError, const QString &message = {}, const QString &out = {}, const QString &err = {});
Code code() const;
QString message() const;
QString out() const;
QString err() const;
private:
Code m_code;
QString m_message;
QString m_out;
QString m_err;
};
......@@ -59,10 +64,10 @@ using FutureResult = QFuture<Result<T>>;
inline
FutureResult<> errorResult(Error::Code error, const QString &message)
FutureResult<> errorResult(Error::Code error, const QString &message, const QString &out = {}, const QString &err = {})
{
qWarning() << message;
return makeReadyFuture(Result<>::error(error, message));
return makeReadyFuture(Result<>::error(error, message, out, err));
}
......
......@@ -66,7 +66,8 @@ Result<> FuseBackend::hasProcessFinishedSuccessfully(QProcess *process)
// otherwise just report that we failed
Result<>::error(Error::CommandError,
i18n("Unable to perform the operation"));
i18n("Unable to perform the operation"),
out, err);
}
......
......@@ -18,11 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mountdialog.h"
#include "engine/vault.h"
#include <QCloseEvent>
#include <QStyle>
#include <QStyleOption>
#include <QAction>
#include <QMessageBox>
#include <KMessageWidget>
......@@ -37,6 +38,28 @@ MountDialog::MountDialog(PlasmaVault::Vault *vault)
m_errorLabel->setIcon(QIcon::fromTheme("dialog-error"));
m_errorLabel->setVisible(false);
m_detailsAction = new QAction(this);
m_detailsAction->setToolTip(i18n("Details..."));
m_detailsAction->setIcon(QIcon::fromTheme("view-list-details"));
connect(m_detailsAction, &QAction::triggered,
this, [this] {
QString message;
const auto out = m_lastError.out().trimmed();
const auto err = m_lastError.err().trimmed();
if (!out.isEmpty() && !err.isEmpty()) {
message = i18n("Command output:\n%1\n\nError output: %2", m_lastError.out(), m_lastError.err());
} else {
message = out + err;
}
auto messageBox = new QMessageBox(QMessageBox::Critical, i18n("Error details"), message, QMessageBox::Ok, this);
messageBox->setAttribute(Qt::WA_DeleteOnClose);
messageBox->show();
});
auto errorLabelSizePolicy = m_errorLabel->sizePolicy();
errorLabelSizePolicy.setHorizontalPolicy(QSizePolicy::Expanding);
m_errorLabel->setSizePolicy(errorLabelSizePolicy);
......@@ -68,9 +91,17 @@ void MountDialog::accept()
if (result) {
QDialog::accept();
} else {
qDebug() << "We've got an error" << result.error().message();
// m_ui.errorLabel->setText(i18n("Failed to open: %1").arg(result.error().message()));
m_errorLabel->setText(i18n("Failed to open: %1", result.error().message()));
m_lastError = result.error();
m_errorLabel->setText(i18n("Failed to open: %1", m_lastError.message()));
m_errorLabel->setVisible(true);
if (!m_lastError.out().isEmpty() || !m_lastError.err().isEmpty()) {
m_errorLabel->addAction(m_detailsAction);
} else {
m_errorLabel->removeAction(m_detailsAction);
}
}
}
......@@ -25,7 +25,10 @@
#include "ui_mountdialog.h"
#include "engine/vault.h"
class KMessageWidget;
class QAction;
namespace PlasmaVault {
class Vault;
......@@ -43,6 +46,8 @@ private:
PlasmaVault::Vault *m_vault;
Ui_MountDialog m_ui;
KMessageWidget* m_errorLabel;
QAction* m_detailsAction;
PlasmaVault::Error m_lastError;
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment