Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the
CodeExecutor
of Tribler used by ApplicationTester does not catch errors properly. To catch errors during the execution of the action, it temporarily replacesstdout
andstderr
withStringIO
objects and then attempts to detect an error by analyzing the output ofstderr
.With the current Tribler code, this approach does not work correctly. To write errors to
stderr
, Python logger createsStreamHandler
object that caches reference tostderr
. WhenCodeExecutor
replacesstderr
toStringIO
object,StreamHandler
continues to write errors to the originalstderr
stream, and the errors go unnoticed byCodeExecutor
.This PR fixes error detection in
CodeExecutor
. Instead of replacing thestderr
stream with theStringIO
object, it defines theshowtraceback
hook that catches exceptions arising during theApplicationTester
action.Also, this PR fixes reporting GUI errors to
stderr
(sometimes, the error was suppressed by logic in thegui_error
handler).The last change is an automatic screenshot taking when an exception occurs in the
CodeExecutor
action evaluation. If the application tester passes theapp_tester_dir
value to the script, it is used as a root directory for screenshot saving.