Error processing SyntaxError exception from a Python Script #2235
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.
When executing a Python script with a syntax error via Windows Scripting Host, the exception always comes back as "Unknown" with Python 3.10, 3.11 and 3.12
Expected behavior:
From Windows OnScriptError( IActiveScriptError * pSE )
EXCEPTINFO eiError;
pSE->GetExceptionInfo( &eiError );
eiError->bstrDescription should contain "invalid syntax" and info for line number and offset should be available.
Actual behavior:
eiError->bstrDescription contains "Unknown" and the line number and offset are 0.
The problem is in class AXScriptException:
The function _BuildFromSyntaxError that parses the SyntaxError exception has a tuple assignment that is failing because two new fields were added in 3.10 (end_lineno and end_offset).
The failing line in _BuildFromSyntaxError is:
(filename, lineno, offset, line) = value[1]
because value[1] starting with Python 3.10 now has six elements.
To be backwardly compatible with Python 3.7, 3.8 and 3.9 and not get an exception in 3.10, 3.11 and 3.12 I have coded:
filename = value[1][0]
lineno = value[1][1]
offset = value[1][2]
line = value[1][3]