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

Add a better way to display errors to users, and implement initial cases (chooser, vcs backend) #10065

Merged
merged 3 commits into from
Jan 23, 2025

Conversation

abn
Copy link
Member

@abn abn commented Jan 17, 2025

This changes introduces the use of PoetryRuntimeError that allows better error information propagation.

Also contained in this change are the following UX improvements.

  1. Error handling when checksum mismatch occurs in Chooser. (Resolves: Poetry cannot install Numpy 2.2.1 #10057)
  2. Error handling for various git commands, including better stdout/stderr representation. (Closes: Expose git errors instead of printing a generic error message #9845 Resolves: Expose git errors instead of printing a generic error message #9819)

Chooser Error Improvements

Before

Screenshot From 2025-01-17 03-14-01

After

Screenshot-chooser-new

After (verbose)

Screenshot From 2025-01-18 19-35-42

Git Error Improvements

Before

Screenshot-git-old-bad-sha

Screenshot-git-old-bad-remote

After

Screenshot-git-new-bad-remote

Screenshot-git-new-bad-sha

After (verbose)

Screenshot-git-new-bad-repo-verbose

Summary by Sourcery

Improve the user experience when a package hash is not found during installation by providing more informative error messages.

Bug Fixes:

  • Fixed an issue where unclear error messages were displayed when package hashes did not match the lock file during installation.

Enhancements:

  • Improved error handling and reporting during package installation.

Summary by Sourcery

Improve error handling and user experience for hash mismatch and various Git commands during package installation.

New Features:

  • Introduced PoetryRuntimeError for better error propagation and formatting.

Bug Fixes:

  • Fixed an issue with unclear error messages when package hashes did not match during installation.

Enhancements:

  • Improved error reporting for Git commands, providing more context and troubleshooting information.

@abn abn added area/error-handling Bad error messages/insufficient error handling area/ux Features and improvements related to the user experience labels Jan 17, 2025
@abn abn requested a review from a team January 17, 2025 02:18
@abn
Copy link
Member Author

abn commented Jan 17, 2025

@sourcery-ai review

1 similar comment
@abn
Copy link
Member Author

abn commented Jan 17, 2025

@sourcery-ai review

Copy link

sourcery-ai bot commented Jan 17, 2025

Reviewer's Guide by Sourcery

This pull request introduces improved error handling and user experience for various scenarios, including checksum mismatches during package installation and errors during git operations. It leverages a new PoetryRuntimeError class to provide more informative error messages and debugging information.

Sequence diagram for improved error handling flow

sequenceDiagram
    participant User
    participant Poetry
    participant Chooser
    participant Git
    participant Console

    User->>Poetry: Run command
    alt Package checksum mismatch
        Poetry->>Chooser: Get package links
        Chooser-->>Poetry: Raise PoetryRuntimeError
        Poetry->>Console: Display formatted error<br/>with debug info
    else Git operation fails
        Poetry->>Git: Execute git command
        Git-->>Poetry: Raise CalledProcessError
        Poetry->>Console: Display formatted error<br/>with command details
    end
    Console-->>User: Show user-friendly error<br/>with debugging hints
Loading

Class diagram for new error handling classes

classDiagram
    class PoetryConsoleError {
        <<CleoError>>
    }
    class GroupNotFoundError {
        <<PoetryConsoleError>>
    }
    class PoetryRuntimeError {
        -messages: list[ConsoleMessage]
        -exit_code: int
        +write(io: IO)
        +get_text(debug: bool, indent: str, strip: bool): str
        +create(reason: str, exception: Exception, info: list[str]): PoetryRuntimeError
    }
    class ConsoleMessage {
        +text: str
        +debug: bool
        +stripped: str
        +wrap(tag: str): ConsoleMessage
        +indent(indent: str): ConsoleMessage
        +make_section(title: str, indent: str): ConsoleMessage
    }
    class PrettyCalledProcessError {
        +message: ConsoleMessage
        +output: ConsoleMessage
        +errors: ConsoleMessage
        +command_message: ConsoleMessage
        +command: str
    }

    PoetryConsoleError <|-- GroupNotFoundError
    PoetryConsoleError <|-- PoetryRuntimeError
    PoetryRuntimeError --> ConsoleMessage
    PrettyCalledProcessError --> ConsoleMessage

    note for PoetryRuntimeError "New class for better error handling"
    note for ConsoleMessage "Handles formatted console output"
    note for PrettyCalledProcessError "Formats subprocess errors"
Loading

File-Level Changes

Change Details Files
Introduce PoetryRuntimeError for better error information propagation.
  • Added ConsoleMessage class for formatting console output.
  • Added PrettyCalledProcessError class for formatting subprocess errors.
  • Added PoetryRuntimeError class for handling runtime errors with detailed messages.
src/poetry/console/exceptions.py
Improve error handling for checksum mismatches in Chooser.
  • Modified _get_links to raise PoetryRuntimeError with detailed information when checksums do not match.
  • Added test case to verify the new error message.
src/poetry/installation/chooser.py
tests/installation/test_chooser.py
Improve error handling for various git commands.
  • Modified _clone_legacy and _clone to raise PoetryRuntimeError with detailed information when git commands fail.
  • Added common error messages for git operations.
  • Modified SystemGit.run to capture output and raise CalledProcessError.
src/poetry/vcs/git/backend.py
src/poetry/vcs/git/system.py
Modify the application to handle PoetryRuntimeError.
  • Modified _run to catch PoetryRuntimeError and write the error message to the console.
  • Modified _execute_operation to handle PoetryRuntimeError and display the error message.
src/poetry/console/application.py
src/poetry/installation/executor.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a 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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/poetry/installation/executor.py Show resolved Hide resolved
tests/installation/test_chooser.py Show resolved Hide resolved
tests/installation/test_chooser.py Show resolved Hide resolved
@abn abn force-pushed the issues/10057 branch 2 times, most recently from f30b118 to b5283cb Compare January 18, 2025 14:00
@abn abn marked this pull request as draft January 18, 2025 18:04
@abn
Copy link
Member Author

abn commented Jan 18, 2025

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a 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: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/poetry/console/exceptions.py Show resolved Hide resolved
@abn abn changed the title feat(ux): add error better ux for hash not found Add a better way to display errors to users, and implement initial cases (chooser, vcs backend) Jan 18, 2025
@abn abn marked this pull request as ready for review January 18, 2025 18:43
src/poetry/console/application.py Outdated Show resolved Hide resolved
src/poetry/console/exceptions.py Show resolved Hide resolved
tests/installation/test_chooser.py Show resolved Hide resolved
@abn abn requested a review from radoering January 22, 2025 18:21
@abn abn requested a review from radoering January 23, 2025 18:18
@abn abn enabled auto-merge (rebase) January 23, 2025 18:44
abn added 3 commits January 23, 2025 19:44
This changes allows better error information propagation to facilitate
improved ux for users encountering errors.

Resolves: python-poetry#10057
@abn abn merged commit 51e1308 into python-poetry:main Jan 23, 2025
58 checks passed
@abn abn deleted the issues/10057 branch January 23, 2025 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/error-handling Bad error messages/insufficient error handling area/ux Features and improvements related to the user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Poetry cannot install Numpy 2.2.1 Expose git errors instead of printing a generic error message
2 participants