GDevelop-extensions icon indicating copy to clipboard operation
GDevelop-extensions copied to clipboard

refactor: Improve Promise Handling, Validation, and Code Efficiency Across Scripts

Open Viole07 opened this issue 4 months ago • 1 comments


Pull Request Description :

Closes #1402

This pull request refactors and improves several scripts in the project by enhancing error handling, improving validation logic, and streamlining promise management. Below are the key changes made across different files:

  1. verifyExtension.js:

    • Refactored promise handling by introducing a try-catch block for consistent async error handling across the function.
    • Replaced the mix of .catch() and async/await with a more streamlined approach, ensuring any unhandled async errors are caught and logged properly.
    • Added detailed error logging to help with debugging during extension verification.
  2. extract-extension.js:

    • Refactored to streamline the promise handling by wrapping the entire function in a try-catch block.
    • This ensures that any errors related to loading or extracting the zip file are handled in a single place, providing more consistent error handling.
    • Improved the error logging by including the actual error message in the returned result for better context during debugging.
  3. ExtensionNameValidator.js:

    • Added a type check for extensionName to ensure it is a string before proceeding with further validation.
    • This prevents potential runtime errors when invalid data types are passed, making the function more robust.
  4. PascalCase.js:

    • Combined two similar loops into a single loop that processes both publicEventsFunctions and eventsBasedBehaviors. This reduces code duplication and simplifies the logic.
    • Added a type check for extension.name to ensure it is a string before validating the PascalCase, preventing errors when the name is not provided or is of the wrong type.

Benefits:

  • Improved code readability and maintainability by consolidating promise handling and reducing redundancy.
  • Increased robustness through added type checks and better error logging, making debugging easier.
  • Simplified logic by combining redundant loops and refactoring validation functions into smaller, reusable components.

Viole07 avatar Oct 09 '24 14:10 Viole07