Skip to content

gladevcp: move return out of finally in SAVE_PROGRAM#4075

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/gtk_action-return-in-finally
Open

gladevcp: move return out of finally in SAVE_PROGRAM#4075
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:fix/gtk_action-return-in-finally

Conversation

@grandixximo
Copy link
Copy Markdown
Contributor

gtk_action.py had return npath inside a finally: block. A return in
finally swallows any in-flight exception and overrides earlier returns,
so the except branch's return None (the error path) was always clobbered:
a failed save still returned the path and hid the exception.

Dedent the return out of the finally so the finally only closes the file.
On success the function returns the path; on a write error it now returns
None. Also silences the Python 3.12+ SyntaxWarning: 'return' in a 'finally'
block.

Surfaced in the ui-smoke review, PR #4054.

Fixes #4067

Test: py_compile clean with no SyntaxWarning; success returns path, write
error returns None.

gtk_action.py had 'return npath' inside a finally: block. A return in
finally swallows any in-flight exception and overrides earlier returns,
so the except branch's 'return None' (the error path) was always
clobbered: a failed save still returned the path and hid the exception.

Dedent the return out of the finally so the finally only closes the
file. On success the function returns npath; on a write error it now
correctly returns None. Also silences the Python 3.12+
SyntaxWarning: 'return' in a 'finally' block.

Surfaced by the ui-smoke tests (PR LinuxCNC#4054).

Fixes LinuxCNC#4067
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.

gladevcp: 'return' inside finally in gtk_action.py swallows exceptions

1 participant