Skip to content

Commit

Permalink
Error processing SyntaxError exception from a Python Script (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbbeatty authored Apr 1, 2024
1 parent 484eeda commit f2b667c
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions com/win32comext/axscript/client/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,35 +98,22 @@ def __BuildFromException(self, site, type, value, tb):
linecache.clearcache()
try:
if issubclass(type, SyntaxError):
self._BuildFromSyntaxError(site, value, tb)
self._BuildFromSyntaxError(value)
else:
self._BuildFromOther(site, type, value, tb)
except: # Error extracting traceback info!!!
traceback.print_exc()
# re-raise.
raise

def _BuildFromSyntaxError(self, site, exc, tb):
value = exc.args
# All syntax errors should have a message as element 0
try:
msg = value[0]
except:
msg = f"Unknown Error ({value})"
try:
(filename, lineno, offset, line) = value[1]
# Some of these may be None, which upsets us!
if offset is None:
offset = 0
if line is None:
line = ""
except:
msg = "Unknown"
lineno = 0
offset = 0
line = "Unknown"
def _BuildFromSyntaxError(self, exc: SyntaxError):
# Some of these may be None, which upsets us!
msg = exc.msg or "Unknown Error"
offset = exc.offset or 0
line = exc.text or ""

self.description = FormatForAX(msg)
self.lineno = lineno
self.lineno = exc.lineno
self.colno = offset - 1
self.linetext = ExpandTabs(line.rstrip())

Expand Down

0 comments on commit f2b667c

Please sign in to comment.