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

feat: split stderr for better error presentation #897

Merged
merged 58 commits into from
Nov 27, 2024
Merged

feat: split stderr for better error presentation #897

merged 58 commits into from
Nov 27, 2024

Conversation

bepri
Copy link
Contributor

@bepri bepri commented Nov 7, 2024

  • Have you signed the CLA?

bepri added 2 commits November 7, 2024 08:46
Adds a fork_utils module for capturing stdout/stderr separately, while also keeping a (best-effort) temporally-accurate combined account of the two.
ForkProcess now prints to the provided stdout/stderr, or nowhere at all if fileno -1 is given
@bepri bepri self-assigned this Nov 7, 2024
bepri added 9 commits November 7, 2024 14:48
StreamHandler objects were closing their pipes before guaranteeing that their associated thread wouldn't attempt to read from them again. This commit should fix that issue.
Raise a unique exception when scripts fail, that way different caller functions can decide how to handle the failure themselves
Moves the raising of ForkError from the caller to the `run()` function itself, additionally adding a `check` parameter for skipping this exception if it should be ignored.
bepri added 11 commits November 8, 2024 14:00
…tibility

Most tests and other modules expect `subprocess.run()` to be called, so the kwargs passed into it are given with the expectation that they'll be handled that way. Instead of changing each call one-by-one, this commit changes `fork_utils.run()` to default to the system's stdout/stderr when given `None` instead of not redirecting output at all.
@cmatsuoka cmatsuoka closed this Nov 12, 2024
@cmatsuoka cmatsuoka reopened this Nov 12, 2024
craft_parts/errors.py Outdated Show resolved Hide resolved
Copy link
Contributor

@tigarmo tigarmo left a comment

Choose a reason for hiding this comment

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

nice thanks!

craft_parts/errors.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
craft_parts/executor/step_handler.py Outdated Show resolved Hide resolved
craft_parts/executor/step_handler.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
bepri and others added 6 commits November 25, 2024 12:25
Co-authored-by: Dariusz Duda <dariusz.duda@canonical.com>
Co-authored-by: Dariusz Duda <dariusz.duda@canonical.com>
To speed up the program and improve code cleanliness, proper BytesIO objects should be used and the file descriptors they read from should be wrapped in a context manager that guarantees they will be closed properly. This commit addresses both statements.
Copy link
Contributor

@dariuszd21 dariuszd21 left a comment

Choose a reason for hiding this comment

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

Thank you for that! It will improve our UX drastically.

My last comments are rather cosmetic and you can ignore them 😄

craft_parts/utils/process.py Show resolved Hide resolved
craft_parts/executor/step_handler.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
@bepri
Copy link
Contributor Author

bepri commented Nov 26, 2024

In craft-application, it was found that tests would fail if they used the capsys fixture with this PR. The capfd fixture is a total drop-in replacement, and in all cases, using it instead of capsys resolves the test failures. It appears that capfd does a "more proper" file redirection. A companion PR in craft-application will be opened to fix those tests.

craft_parts/errors.py Outdated Show resolved Hide resolved
@bepri bepri requested a review from dariuszd21 November 26, 2024 20:30
craft_parts/utils/process.py Outdated Show resolved Hide resolved
craft_parts/utils/process.py Outdated Show resolved Hide resolved
craft_parts/errors.py Show resolved Hide resolved
Copy link
Contributor

@mr-cal mr-cal left a comment

Choose a reason for hiding this comment

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

Nice work!

craft_parts/utils/process.py Outdated Show resolved Hide resolved
@bepri bepri requested a review from sergiusens November 27, 2024 19:35
@bepri bepri merged commit 5bbd983 into main Nov 27, 2024
13 checks passed
@bepri bepri deleted the split-stderr branch November 27, 2024 20:26
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.

Capture stderr from plugin build calls
6 participants