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

Delegate writing mbti files to mooninfo instead of capturing stdout #565

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

Conversation

lynzrand
Copy link
Contributor

Related Issues

closes moonbitlang/moonbit-docs#420

Type of Pull Request

  • Bug fix
  • New feature
    • I have already discussed this feature with the maintainers.
  • Refactor
  • Performance optimization
  • Documentation
  • Other (please describe):

Does this PR change existing behavior?

  • Yes (please describe the changes below)
    • To ensure a consistent line ending between platforms, moon info writing is delegated to mooninfo which writes in a consistent line ending.
  • No

Does this PR introduce new dependencies?

  • No
  • Yes (please check binary size changes)

Checklist:

  • Tests added/updated for bug fixes or new features
  • Compatible with Windows/Linux/macOS

Copy link

peter-jerry-ye-code-review bot commented Jan 15, 2025

‼️ This code review is generated by a bot. Please verify the content before trusting it.

Here are three observations and potential issues from the provided git diff:

  1. Unnecessary Variable Reassignment:

    • The variable filename is being reassigned after it was already derived from filepath. This is redundant and could lead to confusion or errors if the logic changes in the future. The original code calculates filename based on pkg.last_name(), but the new code derives it directly from filepath. Ensure this change is intentional and does not introduce any unintended side effects.
  2. Potential File Extension Mismatch:

    • The code now uses .mbti as the file extension, but it is unclear if this is consistent with the rest of the codebase or the intended behavior. If .mbti is not the standard extension used elsewhere, this could cause issues when other parts of the codebase try to read or process these files.
  3. Error Handling for filepath.file_name():

    • The line let filename = filepath.file_name().unwrap().to_str().unwrap(); uses unwrap() twice, which could panic if file_name() returns None or if to_str() fails (e.g., due to invalid UTF-8 characters). Consider adding proper error handling to avoid runtime crashes. For example:
      let filename = filepath.file_name()
          .ok_or_else(|| anyhow!("Failed to get file name for {:?}", filepath))?
          .to_str()
          .ok_or_else(|| anyhow!("Failed to convert file name to string for {:?}", filepath))?;

These issues should be reviewed and addressed to ensure the code is robust and maintainable.

@lynzrand
Copy link
Contributor Author

This PR is related to an internal change, and should be rerun after the change was merged internally.

@lynzrand lynzrand requested a review from Young-Flash January 15, 2025 07:40
@lynzrand lynzrand force-pushed the rynco/mbti-direct-write branch from 6f366ae to 017231b Compare January 15, 2025 10:28
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.

moon fmt and moon info set newlines inconsistently in Windows
1 participant