GDevelop-extensions
GDevelop-extensions copied to clipboard
refactor: Improve Promise Handling, Validation, and Code Efficiency Across Scripts
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:
-
verifyExtension.js
:- Refactored promise handling by introducing a
try-catch
block for consistent async error handling across the function. - Replaced the mix of
.catch()
andasync/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.
- Refactored promise handling by introducing a
-
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.
- Refactored to streamline the promise handling by wrapping the entire function in a
-
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.
- Added a type check for
-
PascalCase.js
:- Combined two similar loops into a single loop that processes both
publicEventsFunctions
andeventsBasedBehaviors
. 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.
- Combined two similar loops into a single loop that processes both
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.