Updates to uiscripter/actions/runaction - display exception information in output window, provide more context (eg line number, text, offset for syntax errors)
ClosedPublic

Authored by brendanbd on Dec 28 2017, 1:06 PM.

Details

Summary

Improve scripter's exception reporting.
Currently scripter posts a critical QMessage box containing the error text
relating to an exception, but it does not provide the line number or text
where the exception occurred. This requires someone scripting to close the
message box before correcting the issue.
For syntax errors and indent errors it will provide the line number but not
(in the case of syntax errors) any visual indication of the location of the
syntax error.

This diff takes exception handling into runaction.py and provides exception
reporting in the output widget. This removes the dialog box, so script
developers don't need to constantly close a dialog box to edit and rerun their
script. The reporting is minimal, effectively limited to one traceback.
For syntax errors it shows the location of the error.

For example, the code


# Syntax error - progressively uncomment each test
for a in range(15)
print(a)

Should produce the output:


#**********************
#Syntax Error on line 2
#for a in range(15)
# ^
#************

(Only the caret will be correctly positioned, because it'll be shown using a monospaced font...)

For this part of the syntax error reporting to work properly requires that the
output widget uses a monospace font - see https://phabricator.kde.org/D9530

This diff assumes the following revisions have been implemented:
https://phabricator.kde.org/D9527
https://phabricator.kde.org/D9529
https://phabricator.kde.org/D9530

Test Plan


# Syntax error - progressively uncomment each test
#for a in range(15)
# print(a)
#**********************
#Syntax Error on line 2
#for a in range(15)
# ^
#************

# Indentation error
#for a in range(15):
#print(a)

##**********************
#Unexpected Indent on line 12
#print(a)
#**********************

# IndexError
#a = []
#a[0]
#**********************
#IndexError: list index out of range

#In file: <name of file>
#In function: <module> at line: 21. Line with error:
#a[0]
#**********************

## KeyError
#a={}
#a[1]
#**********************
#KeyError: 1

#In file: <name of file>
#In function: <module> at line: 32. Line with error:
#a[1]
#**********************

# Attribute Error
#a=[]
#a.a
#**********************
#AttributeError: 'list' object has no attribute 'a'

#In file: <name of file>
#In function: <module> at line: 43. Line with error:
#a.a
#**********************

#
# Name Error
#a.a
#**********************
#NameError: name 'a' is not defined

#In file: /home/bb/krita/phabricator/test_scripter.py
#In function: <module> at line: 54. Line with error:
#a.a
#**********************

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
brendanbd created this revision.Dec 28 2017, 1:06 PM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptDec 28 2017, 1:06 PM
brendanbd requested review of this revision.Dec 28 2017, 1:06 PM
brendanbd edited the summary of this revision. (Show Details)Dec 28 2017, 1:10 PM
brendanbd edited the test plan for this revision. (Show Details)
rempt accepted this revision.Jan 23 2018, 9:29 AM
This revision is now accepted and ready to land.Jan 23 2018, 9:29 AM
Closed by commit R37:b9a9b7b08d97: Improve Python-> Scripter's exception reporting (authored by Brendan Bd <bunf2014@apps.opensourcelaw.biz>). · Explain WhyJan 25 2018, 11:03 PM
This revision was automatically updated to reflect the committed changes.