-
Notifications
You must be signed in to change notification settings - Fork 11
Update subprocess types and improve error handling in run.py #485
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
Conversation
Reviewer's Guide by SourceryThis pull request improves the reliability and maintainability of the Sequence diagram for run function with improved error handlingsequenceDiagram
participant User
participant run
participant subprocess.Popen
participant proc.stdout
participant proc.stderr
participant CommandError
User->>run: run(args, ...)
run->>subprocess.Popen: Popen(args, stdout=PIPE, stderr=PIPE, ...)
subprocess.Popen-->>run: proc
loop Read stdout lines
run->>proc.stdout: readlines()
proc.stdout-->>run: line
run->>run: Filter and join stdout lines
end
alt code != 0 and check_returncode
loop Read stderr lines
run->>proc.stderr: readlines()
proc.stderr-->>run: line
run->>run: Filter and join stderr lines
end
run->>CommandError: raise CommandError(output, returncode, cmd)
CommandError-->>User: Exception
else code == 0 or not check_returncode
run-->>User: output
end
Updated class diagram for CommandErrorclassDiagram
class CommandError {
+output: str
+returncode: int
+cmd: str | list[str]
+__init__(output: str, returncode: int, cmd: str | list[str])
}
note for CommandError "cmd is now explicitly converted to string"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #485 +/- ##
=======================================
Coverage 54.08% 54.09%
=======================================
Files 40 40
Lines 3635 3627 -8
Branches 793 793
=======================================
- Hits 1966 1962 -4
+ Misses 1318 1314 -4
Partials 351 351 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tony - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using
io.TextIOWrapper
to handle encoding and decoding directly when reading from stdout/stderr.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
3ba540f
to
4dcd9db
Compare
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tony - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using
io.TextIOWrapper
to avoid manual encoding/decoding. - The error messages could be improved by including the command that failed.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
a933a65
to
f47cfd2
Compare
@sourcery-ai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @tony - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider using
subprocess.run
directly instead of wrapping it, as it provides similar functionality with a more standard interface. - The type annotation changes look good, but ensure they align with the actual types returned by the subprocess methods to avoid runtime errors.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
49750a7
to
aa03d5f
Compare
uv run ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; uv run ruff format . Fixed 6 errors: - src/libvcs/_internal/subprocess.py: 3 × PYI061 (redundant-none-literal) 3 × UP045 (non-pep604-annotation-optional)
9653f76
to
d4015ff
Compare
@sourcery-ai review |
Changes
Technical Details
Type System Improvements:
stdout_lines
andstderr_lines
aslist[bytes]
cmd
argument type inCommandError
by ensuring string conversionError Handling:
PIPE_NOT_SET_ERR
constant for consistent error messagingCode Quality:
filter(None, ...)
with list comprehension for better readabilityall_output
to maintain consistent typesTesting
Impact
These changes improve code reliability and maintainability without changing the underlying behavior. The updates make the code more robust by:
Summary by Sourcery
Improve error handling and type annotations in the
run
function. Standardize error messages using constants and ensure consistent type handling for outputs. No user-facing behavior changes are included.Bug Fixes:
RuntimeError
caused by unchecked file descriptors in therun
function.all_output
to maintain consistent types across different code pathsChores:
run
module using more concise imports from thetyping
module.PIPE_NOT_SET_ERR
for consistent error messaging related to file descriptors.filter(None, ...)
with list comprehension for improved readability.Summary by Sourcery
Improves error handling and type annotations in the
run
function. Standardizes error messages using constants and ensures consistent type handling for outputs.Bug Fixes:
all_output
to maintain consistent types across different code paths.Enhancements:
run
module using more concise imports from thetyping
module.filter(None, ...)
with list comprehension for improved readability.Chores:
PIPE_NOT_SET_ERR
for consistent error messaging related to file descriptors.