Skip to content

Commit

Permalink
Use scrollable view for long error messages; closes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
probonopd committed Oct 8, 2023
1 parent 1251de3 commit 0fb26d7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
9 changes: 9 additions & 0 deletions src/ApplicationSelectionDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,14 @@ QString ApplicationSelectionDialog::getSelectedApplication()

}

// Touch the file and its parent directory so that Filer updates its icon
QFileInfo fileInfo(*fileOrProtocol);
if (fileInfo.exists()) {
QProcess process;
qDebug() << "Touching parent directory: " << fileInfo.dir().path();
process.start("touch", QStringList() << fileInfo.dir().path());
process.waitForFinished();
}

return ui->listWidget->selectedItems().first()->text();
}
46 changes: 25 additions & 21 deletions src/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void Launcher::handleError(QDetachableProcess *p, QString errorString)
{
QMessageBox qmesg;

QFileInfo fi(p->program());
QString title = fi.completeBaseName(); // https://doc.qt.io/qt-5/qfileinfo.html#completeBaseName

// Make this error message not appear in the Dock // FIXME: Does not work,
// why?
qmesg.setWindowFlag(Qt::SubWindow);
Expand All @@ -59,8 +62,7 @@ void Launcher::handleError(QDetachableProcess *p, QString errorString)

QRegExp rx(".*ld-elf.so.1: (.*): version (.*) required by (.*) not found.*");
QRegExp rxPy(".*ModuleNotFoundError: No module named '(.*)'.*");
QFileInfo fi(p->program());
QString title = fi.completeBaseName(); // https://doc.qt.io/qt-5/qfileinfo.html#completeBaseName

if (errorString.contains("FATAL: kernel too old")) {
QString cleartextString =
"The Linux compatibility layer reports an older kernel version than "
Expand All @@ -78,9 +80,10 @@ void Launcher::handleError(QDetachableProcess *p, QString errorString)
QFileInfo fileInfo(f.fileName());
QString outdatedLibShort(fileInfo.fileName());
QString cleartextString =
QString("This application requires at least version %2 of %1 to run.")
.arg(outdatedLibShort)
.arg(versionNeeded);
QString("%1 application requires at least version %2 of %3 to run.")
.arg(title)
.arg(versionNeeded)
.arg(outdatedLibShort);
if (getPackageUpdateCommand(outdatedLib) != "") {
cleartextString.append(QString("\n\nPlease update it with\n%1\nand try again.")
.arg(getPackageUpdateCommand(outdatedLib)));
Expand All @@ -91,13 +94,13 @@ void Launcher::handleError(QDetachableProcess *p, QString errorString)
qmesg.warning(nullptr, title, cleartextString);
} else if (rxPy.indexIn(errorString) == 0) {
QString missingPyModule = rxPy.cap(1);
QString cleartextString = QString("This application requires the Python module %1 to "
QString cleartextString = QString("%1 requires the Python module %2 to "
"run.\n\nPlease install it and try again.")
.arg(title)
.arg(missingPyModule);
qmesg.warning(nullptr, title, cleartextString);
} else {
// Show the first 10 lines of the error message, then ..., then the last 10
// lines

QStringList lines = errorString.split("\n");

// Remove all lines from QStringList lines that contain "from LD_PRELOAD
Expand All @@ -112,22 +115,23 @@ void Launcher::handleError(QDetachableProcess *p, QString errorString)
}
}

QString cleartextString = "";
for (int i = 0; i < 10; i++) {
if (i < lines.length()) {
cleartextString.append(lines[i] + "\n");
}
}
QString cleartextString = lines.join("\n");
if (lines.length() > 10) {
cleartextString.append("...\n");

for (int i = lines.length() - 10; i < lines.length(); i++) {
if (i < lines.length()) {
cleartextString.append(lines[i] + "\n");
}
}
QString text = QObject::tr(QString("%1 has quit unexpectedly.\n\n\n").arg(title).toUtf8());
// Append non-breaking spaces to the text to increase width
text.append(QString(100, QChar::Nbsp));
qmesg.setText(text);
QString informativeText = QObject::tr("Error message:");
qmesg.setWindowTitle(title);
qmesg.setDetailedText(cleartextString);
qmesg.setIcon(QMessageBox::Warning);
qmesg.setSizeGripEnabled(true);
qmesg.exec();
} else {
qmesg.warning(nullptr, title, cleartextString);
}
qmesg.warning(nullptr, title, cleartextString);

}
}

Expand Down
8 changes: 8 additions & 0 deletions tests/errortest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python3

import sys

for i in range(50):
print("error output", i, file=sys.stderr)

sys.exit(1)

0 comments on commit 0fb26d7

Please sign in to comment.