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(app): add better error for removed commands #10053

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

abn
Copy link
Member

@abn abn commented Jan 15, 2025

In cases like the shell command, where it has been moved to a plugin, allow Poetry to provide a better UX when these commands are called.

When rendered this looks like the following.

image

Summary by Sourcery

Tests:

  • Add tests for removed command error messages.

@abn abn requested a review from a team January 15, 2025 17:44
Copy link

sourcery-ai bot commented Jan 15, 2025

Reviewer's Guide by Sourcery

This pull request implements a better user experience for removed commands, such as the shell command. Now, instead of a generic error, Poetry provides a more informative message guiding users on alternative actions.

Sequence diagram for handling removed commands

sequenceDiagram
    actor User
    participant App as Poetry Application
    participant ErrorHandler as Command Not Found Handler

    User->>App: Execute removed command (e.g., 'shell')
    App->>ErrorHandler: Check if command exists
    alt Command is in COMMAND_NOT_FOUND_MESSAGES
        ErrorHandler->>User: Display custom error message with alternatives
    else Command not in special messages
        ErrorHandler->>User: Display standard command not found error
    end
Loading

Class diagram for Application error handling changes

classDiagram
    class Application {
        -dict COMMAND_NOT_FOUND_MESSAGES
        -str COMMAND_NOT_FOUND_PREFIX_MESSAGE
        +_run(IO io) int
    }
    note for Application "Added error handling for
removed commands"

    class CleoCommandNotFoundError {
        +str message
    }

    Application ..> CleoCommandNotFoundError: handles
Loading

File-Level Changes

Change Details Files
Added a new fixture command_factory to create mock commands for testing.
  • Created a new fixture command_factory that generates mock commands with customizable attributes like name, arguments, options, description, help text, and handler.
  • The factory function allows for flexible creation of mock commands for different test scenarios.
  • This fixture simplifies the process of creating mock commands for testing purposes by providing a centralized factory function with customizable options.
  • The command_factory fixture improves the testability of commands by allowing for the creation of mock commands with specific behaviors and attributes.
  • This fixture enhances the overall testing framework by providing a more streamlined and efficient way to create mock commands for various test cases.
  • The command_factory fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
  • This fixture is used to create mock commands for testing purposes, allowing for greater control over the command's behavior and attributes.
tests/conftest.py
Improved error handling for removed commands in the Poetry application.
  • Added custom error messages for specific removed commands, such as shell, to guide users.
  • Implemented logic to display these custom messages when a removed command is invoked.
  • Added a new test file to verify the behavior of removed commands and their custom error messages.
  • Added a CommandFactory type definition to facilitate the creation of mock commands for testing.
  • The application now catches CleoCommandNotFoundError and displays specific messages for removed commands.
  • Added tests to verify that the correct error messages are displayed for removed commands.
  • Tests also confirm that the default error message is shown for nonexistent commands.
  • The COMMAND_NOT_FOUND_MESSAGES dictionary stores the custom messages for each removed command.
  • The Application._run method now handles the CleoCommandNotFoundError and displays the appropriate message based on the command name.
  • The test_application_removed_command_messages test function verifies that the custom messages are displayed correctly.
  • The test_application_removed_command_default_message test function ensures that the default error message is shown for nonexistent commands.
src/poetry/console/application.py
tests/console/test_application_removed_commands.py
tests/types.py
Added type annotations for improved type checking.
  • Added type annotations to the conftest.py file to improve type checking and code clarity.
  • Added type annotations to the types.py file to improve type checking and code clarity.
  • The CommandFactory protocol was added to tests/types.py to define the type signature for the command factory function.
  • Type annotations were added to the project_context fixture in tests/conftest.py to improve type checking.
  • Import statements were updated in tests/conftest.py to include necessary types for annotations.
  • The Command type annotation was added to the command_handler parameter in the CommandFactory protocol.
tests/conftest.py
tests/types.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: all looks good
  • 🟢 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.

@abn abn force-pushed the fix/cmd-shell-error branch from 8e77707 to fdbff64 Compare January 16, 2025 09:57
@abn abn enabled auto-merge (rebase) January 16, 2025 09:57
@abn abn added area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling area/ux Features and improvements related to the user experience labels Jan 17, 2025
In cases like the `shell` command, where it has been moved to a plugin,
allow Poetry to provide a better UX when these commands are called.
@abn abn force-pushed the fix/cmd-shell-error branch from fdbff64 to 06b7728 Compare January 17, 2025 16:33
@abn abn merged commit ed15d09 into python-poetry:main Jan 17, 2025
73 checks passed
@abn abn deleted the fix/cmd-shell-error branch January 17, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Related to the command line 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.

2 participants