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

Send ruff's stderr to os.devnull #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

hukkin
Copy link

@hukkin hukkin commented Nov 3, 2024

Inspired by discussion here hukkin/mdformat#435

IMO error output from commands mdformat calls in a subprocess should not be shown to the user.

Summary by CodeRabbit

  • Bug Fixes
    • Suppressed error messages during the execution of the Python formatting command, enhancing user experience by reducing unnecessary output.

Copy link

coderabbitai bot commented Nov 3, 2024

Walkthrough

The changes involve a modification to the format_python function within the mdformat_ruff/__init__.py file. Specifically, the subprocess.check_output call has been updated to include the stderr=subprocess.DEVNULL argument. This change suppresses any error messages generated during the execution of the command, while the overall functionality of the function remains unchanged.

Changes

File Change Summary
mdformat_ruff/init.py Modified format_python function to include stderr=subprocess.DEVNULL in check_output call to suppress error messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant FormatFunction
    participant Ruff

    User->>FormatFunction: Call format_python()
    FormatFunction->>Ruff: Execute formatting command
    Ruff-->>FormatFunction: Return formatted output
    FormatFunction-->>User: Return formatted output
Loading

🐰 In the meadow, where bunnies play,
A change was made, hip-hip-hooray!
Errors silenced, smooth and bright,
Formatting code, a pure delight!
With every hop, we cheer and sing,
For happy coding, let joy take wing! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@hukkin
Copy link
Author

hukkin commented Nov 3, 2024

Unrelated to this PR, but since there is no issue tracker in this repository:
May I suggest adding this repository under https://github.com/topics/mdformat Github topic so people are more likely to discover it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
mdformat_ruff/__init__.py (1)

20-22: Consider documenting the stderr suppression.

Since this is an intentional UX decision to suppress stderr, it would be helpful to document this behavior in the docstring.

Here's a suggested update to the docstring:

 def format_python(unformatted: str, _info_str: str) -> str:
     r"""Format python.
 
     :param unformatted:
     :type unformatted: str
     :param _info_str:
     :type _info_str: str
     :rtype: str
+    
+    Note: stderr from the ruff formatter is suppressed to maintain clean output.
+    Formatting errors are still raised through CalledProcessError.
     """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6cd00a4 and d08715b.

📒 Files selected for processing (1)
  • mdformat_ruff/__init__.py (1 hunks)
🔇 Additional comments (1)
mdformat_ruff/__init__.py (1)

20-22: LGTM! Verify error handling remains intact.

The change to suppress stderr aligns with the goal of providing a cleaner output experience. The error handling through subprocess.check_output remains intact as it will still raise CalledProcessError on formatting failures.

Let's verify the error handling behavior:

✅ Verification successful

Error handling is properly implemented through subprocess.check_output

The code correctly relies on subprocess.check_output's built-in error handling, which raises CalledProcessError if the command returns a non-zero exit code. Suppressing stderr with subprocess.DEVNULL only affects the visibility of error messages, not the actual error propagation. This is appropriate for a formatting tool where errors should be handled by the parent mdformat interface.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the code properly handles formatting errors
# Look for try/except blocks or error handling around subprocess calls

# Search for error handling patterns
rg -A 5 "try:|except:|raise|error|Exception" mdformat_ruff/

Length of output: 61


Script:

#!/bin/bash
# Let's check the entire content of the file to understand the error handling context
cat mdformat_ruff/__init__.py

Length of output: 559

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.

1 participant