Skip to content
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

Do not silence subprocess's exit code and avoid polluting stdout #31

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

loathingKernel
Copy link
Contributor

@loathingKernel loathingKernel commented Feb 19, 2024

This PR aims to address the following issues.

  • Capture and return the exit code from the subprocess to the caller in case ULWGL itself was executed successfully. The caller might use the exit code to identify issues in the execution of the subprocess or ULWGL itself. Note: the ruff check was explicitly disabled because the exception at line is used for logging, similar to the patterns ruff ignores by default

  • ULWGL should use stderr only for its own logging to avoid polluting stdout where the caller might expect the result of the argument command. Examples of such internal commands are winepath.exe and reg.exe where the output can be used by the caller.

@R1kaB3rN Since you are actively working on the python code and they might cause conflicts, feel free to either cherry-pick or merge by hand any of these changes if you agree with them. I also updated a few long strings to not exceed the 100th column to make the code slightly easier to parse.

ulwgl_run.py Outdated Show resolved Hide resolved
R1kaB3rN added a commit that referenced this pull request Feb 19, 2024
Co-authored-by: Stelios Tsampas <[email protected]>

- Do not print to stdout when finding or downloading Proton as it is not intended to be processed directly as input for other applications.

- Related to #31 (comment)
ulwgl_run.py Outdated
print(f"{e}", file=sys.stderr)
sys.exit(1)
else:
sys.exit(ret)
Copy link
Member

Choose a reason for hiding this comment

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

Please correct me if I am wrong, but print_tb just formats the traceback nicely compared to simply raising the exception, correct?

Copy link
Contributor Author

@loathingKernel loathingKernel Feb 19, 2024

Choose a reason for hiding this comment

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

Yes and no, print_tb is the way to print the traceback from the exception object, but ideally here, if logging is implemented, the print_tb and print calls should be replaced with logging.excpetion. This was an intermediate solution without using logging

The point here is to not simply raise the exception and exit due to it, but handle it, print the information and exit with an exit code of our choice.

ulwgl_run.py Show resolved Hide resolved
ulwgl_run.py Show resolved Hide resolved
ulwgl_run.py Outdated Show resolved Hide resolved
ulwgl_run.py Outdated Show resolved Hide resolved
ulwgl_run.py Outdated
ret = main()
except Exception as e: # noqa: BLE001
traceback.print_tb(e.__traceback__, file=sys.stderr)
print(f"{e}", file=sys.stderr)
Copy link
Member

Choose a reason for hiding this comment

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

Because of the above line, we shouldn't have to print twice, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of print_tb it was required to get the message. It was printing only the traceback. In case print_exception behaves differently, I will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

No, I believe this is unnecessary and I've confirmed this when using print_exception on a syntax error

* Return the exitcode of the subprocess from `main` in case the caller
wants to do something this it.

* Catch any exceptions during execution and return an error exitcode.
* Avoid polluting `stdout` since the caller might expect the output of
the command there.
@R1kaB3rN R1kaB3rN merged commit c116d7d into Open-Wine-Components:main Feb 19, 2024
2 checks passed
@loathingKernel loathingKernel deleted the stderr branch February 19, 2024 20:36
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.

2 participants