Skip to content

Fix Python failure handling in Pythonwin/pywin/framework/scriptutils.py #2319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Jul 25, 2024

and improve error message

The previous code would produce a TypeError: cannot unpack non-iterable SyntaxError object on SyntaxError

else:
traceback.print_exc()
win32ui.SetStatusText("Failed to " + what + " - " + str(details))
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
Copy link
Collaborator Author

@Avasam Avasam Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deduplicated win32ui.SetStatusText.

I have also considered the following:

Suggested change
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
win32ui.SetStatusText(f"Failed to {what} - {details!r}")

else:
traceback.print_exc()
win32ui.SetStatusText("Failed to " + what + " - " + str(details))
win32ui.SetStatusText(f"Failed to {what} - {type(details)} - {details}")
tb = None # Clean up a cycle.
Copy link
Collaborator Author

@Avasam Avasam Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this tb = None do exactly?

@Avasam Avasam force-pushed the scriptutils-handle-failure branch from c851363 to d285d40 Compare October 4, 2024 22:56
@Avasam Avasam requested a review from mhammond October 18, 2024 18:40
try:
msg, (fileName, line, col, text) = details
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code would produce:
TypeError: cannot unpack non-iterable SyntaxError object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant