-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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(ux): add error better ux for hash not found #10065
base: main
Are you sure you want to change the base?
Conversation
This changes introduces the use of `PoetryRuntimeError` that allows better error information propagation to facilitate improved ux for users encountering errors. Resolves: python-poetry#10057
@sourcery-ai review |
1 similar comment
@sourcery-ai review |
Reviewer's Guide by SourceryThis PR introduces the Sequence diagram for hash mismatch error handlingsequenceDiagram
participant Chooser as Package Chooser
participant Error as PoetryRuntimeError
participant Executor as Executor
participant IO as IO Interface
Chooser->>Error: create(reason, messages)
Note over Chooser,Error: Hash mismatch detected
Error->>Error: format messages
Executor->>Error: get_text(verbose, indent)
Error->>IO: write error message
Note over IO: Display formatted error<br/>with optional debug info
Class diagram for new error handling classesclassDiagram
class CleoError {
}
class PoetryConsoleError {
}
class GroupNotFoundError {
}
class ConsoleMessage {
+str text
+bool debug
+str stripped()
}
class PoetryRuntimeError {
-list[ConsoleMessage] _messages
-int exit_code
+__init__(reason: str, messages: list[ConsoleMessage], exit_code: int)
+write(io: IO)
+get_text(debug: bool, indent: str, strip: bool) str
+__str__() str
}
CleoError <|-- PoetryConsoleError
PoetryConsoleError <|-- GroupNotFoundError
PoetryConsoleError <|-- PoetryRuntimeError
PoetryRuntimeError o-- ConsoleMessage
note for PoetryRuntimeError "New class for improved error handling"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 @abn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟢 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.
reason = f"Downloaded distributions for {package.name} ({package.version}) did not match any known checksums in your lock file." | ||
assert str(e.value) == reason | ||
|
||
text = e.value.get_text(debug=True, strip=True) | ||
assert reason in text | ||
assert files[0]["hash"] in text |
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.
suggestion (testing): Test both debug and non-debug text.
It would be beneficial to also test the non-debug version of the error message to ensure that the correct information is displayed to users in both verbose and non-verbose modes.
reason = f"Downloaded distributions for {package.name} ({package.version}) did not match any known checksums in your lock file." | |
assert str(e.value) == reason | |
text = e.value.get_text(debug=True, strip=True) | |
assert reason in text | |
assert files[0]["hash"] in text | |
reason = f"Downloaded distributions for {package.name} ({package.version}) did not match any known checksums in your lock file." | |
assert str(e.value) == reason | |
# Test non-debug error message | |
text = e.value.get_text(debug=False, strip=True) | |
assert reason in text | |
assert files[0]["hash"] not in text # Hash should not be included in non-debug output | |
# Test debug error message | |
debug_text = e.value.get_text(debug=True, strip=True) | |
assert reason in debug_text | |
assert files[0]["hash"] in debug_text # Hash should be included in debug output |
text = e.value.get_text(debug=True, strip=True) | ||
assert reason in text | ||
assert files[0]["hash"] in text | ||
|
||
|
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.
suggestion (testing): Add tests for multiple mismatched hashes.
Consider adding a test case where multiple files have mismatched hashes to ensure the error message handles this scenario correctly. The current tests only cover a single mismatch.
text = e.value.get_text(debug=True, strip=True) | |
assert reason in text | |
assert files[0]["hash"] in text | |
text = e.value.get_text(debug=True, strip=True) | |
assert reason in text | |
assert files[0]["hash"] in text | |
def test_chooser_with_multiple_mismatched_hashes(package, chooser): | |
files = [ | |
{ | |
"name": "demo-0.1.0.tar.gz", | |
"hash": "incorrect_hash_1", | |
"url": "https://files.pythonhosted.org/demo-0.1.0.tar.gz", | |
}, | |
{ | |
"name": "demo-0.1.0-py2.py3-none-any.whl", | |
"hash": "incorrect_hash_2", | |
"url": "https://files.pythonhosted.org/demo-0.1.0-py2.py3-none-any.whl", | |
} | |
] | |
package.files = files | |
with pytest.raises(PoetryRuntimeError) as e: | |
chooser.choose_for(package) | |
reason = f"Downloaded distributions for {package.name} ({package.version}) did not match any known checksums in your lock file." | |
assert str(e.value) == reason | |
text = e.value.get_text(debug=True, strip=True) | |
assert reason in text | |
# Verify both mismatched hashes are mentioned in the error | |
assert files[0]["hash"] in text | |
assert files[1]["hash"] in text | |
This changes introduces the use of
PoetryRuntimeError
that allows better error information propagation to facilitate improved ux for users encountering errors.Resolves: #10057
Before
After
After (verbose)
After (Multiple)
Summary by Sourcery
Improve the user experience when a package hash is not found during installation by providing more informative error messages.
Bug Fixes:
Enhancements: