[KProcessRunner] Improve error messages on failure
Needs RevisionPublic

Authored by ahmadsamir on Feb 7 2020, 4:19 PM.

Details

Reviewers
dfaure
davidedmundson
broulik
Group Reviewers
Frameworks
Summary

Change the message that's displayed when we can't find an executable
to mention the word "executable", because the binary could be there
but with wrong permissions.

If we find an executable but it exits abnormally (exit code != 0 ),
inform the user about that and suggest he tries running it from terminal
to get more details.

Test Plan

(Proceed with the sudo commands at your own risk):

  • 'sudo chmod a-x /usr/bin/gwenview' then try opening a picutre with gwenview from e.g. dolphin, see the error message
  • 'sudo chmod a+x /usr/bin/gwenview && sudo mv /usr/lib64/libKF5Kipi.so.32.0.0 /usr/' then try opening a picture with gwenview from dolphin, see the error message
  • Finally 'sudo mv /usr/libKF5Kipi.so.32.0.0 /usr/lib64/' to un-break your system

BUG: 415567
FIXED-IN: 5.70

Diff Detail

Repository
R241 KIO
Branch
l-kprunner-message (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 24796
Build 24814: arc lint + arc unit
ahmadsamir created this revision.Feb 7 2020, 4:19 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptFeb 7 2020, 4:19 PM
ahmadsamir requested review of this revision.Feb 7 2020, 4:19 PM
ahmadsamir planned changes to this revision.Feb 7 2020, 6:39 PM
ahmadsamir requested review of this revision.Feb 9 2020, 8:52 AM

krununittest fails to pass, I tried to debug it but can't get it to work. Disabling the third row "QTest::newRow("tempfile") << true << false;" in KRunUnitTest::KRunRunService_data, makes it pass... I can't figure it out.

31: PASS   : KRunUnitTest::KRunRunService(standard)
31: command= "cp %f %d/dest" args= ("cp %f %d/dest", "file:///tmp/krununittest-lvuRpo/srcfile")
31: EXEC "/usr/bin/cp /tmp/krununittest-lvuRpo/srcfile /tmp/krununittest-lvuRpo//dest"
31: EXEC done
31: sleeping for 180 seconds before deleting file...
31: PASS   : KRunUnitTest::KRunRunService(tempfile)
31: QWARN  : KRunUnitTest::KRunRunService(runApp) "The executable 'cp' terminated abnormally.\nFor more details try running it from a terminal emulator (e.g. Konsole)."
31: QFATAL : KRunUnitTest::KRunRunService(runApp) QWidget: Cannot create a QWidget without QApplication
31: FAIL!  : KRunUnitTest::KRunRunService(runApp) Received a fatal error.
31:    Loc: [Unknown file(0)]
31: Totals: 30 passed, 1 failed, 0 skipped, 0 blacklisted, 387ms
31: ********* Finished testing of KRunUnitTest *********
1/1 Test #31: kiowidgets-krununittest ..........Child aborted***Exception:   0.40 sec

And jobtest fails with:
8: FAIL! : JobTest::moveDestAlreadyExistsAutoRename(files other partition) Compared values are not the same
8: Actual (spyRenamed.count()): 3
8: Expected (2) : 2
8: Loc: [/home/ahmad/rpmbuild/dev/kio/autotests/jobtest.cpp(1656)]

and the same with "(dirs other partition)", but that is unrelated AFAICS.

ahmadsamir abandoned this revision.Apr 5 2020, 4:57 AM
dfaure added a comment.Apr 5 2020, 7:24 AM

Oops I totally missed this one, sorry.

Does this testcase work better with the new code in kiogui? Hopefully QProcess start should fail?

ahmadsamir updated this revision to Diff 79399.Apr 5 2020, 12:47 PM
ahmadsamir retitled this revision from [KProcessRunner] Improve error reported to user when exit code != 0 to [KProcessRunner] Improve error messages on failure.
ahmadsamir edited the summary of this revision. (Show Details)
ahmadsamir edited the test plan for this revision. (Show Details)

Update and rebase

The QSignalSpy stuff are fixed.

However, krununittest won't work with QTEST_GUILESS_MAIN() as there's a dialog that wants to get displayed (from my previous post). However I still can't figure out why the cp command is existing with code 15...

dfaure requested changes to this revision.Apr 5 2020, 5:09 PM
dfaure added inline comments.
src/gui/kprocessrunner.cpp
279

Now that KProcessRunner is in KioGui, it's not supposed to use any message boxes.

It's used by jobs which emit errors, so it should just pass along the error.

HOWEVER the jobs finish as soon as the application has started.
By the time the process exits, the job is already gone and we have no way to relay errors to the user.

We don't want jobs to keep running for 5 hours if the application is used for 5 hours. The success of the job is that the application started, not that it finished.

But maybe we should reconsider this. E.g. the job could survive for just another second, to wait for very early exits like this one.

This revision now requires changes to proceed.Apr 5 2020, 5:09 PM

Note that D29153 affects this since it will detect the lack of +x ahead of time in ApplicationLauncherJob and prompt the user [if the application uses KIOWidgets' JobUiDelegate -- oh I need to do this in KRun, will do right away].

Technically this code path will still exist, but the (first) described testcase will not end up there anymore (once D29153 lands).

Please ignore my previous comment. When launching gwenview by clicking on an image (and not on the gwenview executable itself), we indeed do end up with KProcessRunner failing to find the executable because of the missing -x.
I'll implement the proper investigation and error message.

Done in D29170. Now we can start discussing the other part of the bug, executable doesn't launch due to missing libs.

Ah BTW the unittest leads to "cp" failing because it deletes the temporary dir under cp's feet. This could be fixed, but in any case, we don't want to pop up an error message on every process that terminates with a non-0 exit code. Imagine launching firefox, using it for 2 hours, then it crashes, and you get - in addition to drkonqi - that messagebox saying "It terminated abnormally. For more details try running it from a terminal emulator (e.g. Konsole)" .... I think at most we want to let the job run for 5 more seconds to handle "crash on startup", but not react on longer-running programs that terminate abnormally.