moonbitlang / moon

The build system and package manager for MoonBit
https://moonbitlang.github.io/moon/
GNU Affero General Public License v3.0
188 stars 17 forks source link

fix: avoid panic by checking whether name is empty #446

Closed HerrCai0907 closed 3 weeks ago

HerrCai0907 commented 3 weeks ago

Empty name field in moon.mod.json will crash moon when calculate Package.last_name. Check this case before make error message more readable.

Related Issues

Type of Pull Request

Does this PR change existing behavior?

Does this PR introduce new dependencies?

Checklist:

peter-jerry-ye-code-review[bot] commented 3 weeks ago

From the provided git diff output, here are three observations and suggestions for potential issues:

  1. Empty name Field in moon.mod.json:

    • Problem: The name field in the moon.mod.json file is empty. This can lead to issues in identifying the module correctly.
    • Suggestion: Ensure the name field is populated with a valid and meaningful name for the module. This will help in managing dependencies and identifying the module correctly in the ecosystem.
  2. New Test Case for Empty Name:

    • Problem: A new test case (test_empty_name) has been added to check for an empty name in the moon.mod.json file. This test case expects an error to be thrown if the name field is empty.
    • Suggestion: While having test cases to validate such scenarios is good, ensure that the error message and handling are clear and informative. The error message should guide the user on how to fix the issue.
  3. Error Handling for Empty Name in common.rs:

    • Problem: A new error type (NameError::EmptyName) has been introduced to handle the scenario where the name field is empty.
    • Suggestion: Ensure that this error is consistently used across the codebase where the name field is validated. This will help in maintaining a uniform error handling mechanism. Additionally, consider adding more descriptive messages or additional checks if the name field has other constraints (e.g., length, format).

These observations highlight the importance of validating and managing metadata fields like name in module definitions. Ensuring these fields are correctly populated and validated can prevent issues related to module identification and management in larger projects.