Skip to content

Commit

Permalink
#606 - handle user running invalid Python code (#608)
Browse files Browse the repository at this point in the history
see #606 for more details. with this commit, when invalid Python code is called by user, TagUI continues operation and the error message is stored in py_result. before this change, TagUI hangs as the Python process does not return response.
  • Loading branch information
kensoh committed Nov 2, 2019
1 parent 10fc36f commit 3ee145d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/tagui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ chrome_command="google-chrome"

if [ -z "$1" ]
then
echo "tagui v5.9: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo "tagui v5.10: use following options and this syntax to run - ./tagui flow_filename option(s)"
echo
echo "chrome - run on visible Chrome web browser instead of invisible PhantomJS (first install Chrome)"
echo "headless - run on invisible Chrome web browser instead of default PhantomJS (first install Chrome)"
Expand Down
2 changes: 1 addition & 1 deletion src/tagui.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rem enable windows for loop advanced flow control
setlocal enableextensions enabledelayedexpansion

if "%~1"=="" (
echo tagui v5.9: use following options and this syntax to run - tagui flow_filename option^(s^)
echo tagui v5.10: use following options and this syntax to run - tagui flow_filename option^(s^)
echo.
echo chrome - run on visible Chrome web browser instead of invisible PhantomJS ^(first install Chrome^)
echo headless - run on invisible Chrome web browser instead of default PhantomJS ^(first install Chrome^)
Expand Down
9 changes: 7 additions & 2 deletions src/tagui_py/tagui_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ def py_intent ( raw_intent ):
except NameError:
temp_output = sys.stdout = sys.stderr = io.StringIO()

exec(params,globals())
# try/except for user sending invalid Python code
try:
exec(params,globals())
temp_result = temp_output.getvalue().strip()
except Exception as e:
temp_result = str(e)

sys.stdout = old_stdout
sys.stderr = old_stderr
temp_result = temp_output.getvalue().strip()

if temp_result != '':
print(temp_result)
Expand Down

0 comments on commit 3ee145d

Please sign in to comment.