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

Improve error handling and refactor URL validation #36

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

mitsuki31
Copy link
Owner

Notable Changes

This pull request addresses the following changes:

Fixes

  • Error Handling in writeErrorLog:
    • Modified the writeErrorLog function to include a reject handler for stream errors. This ensures that any error encountered during the logging process is properly handled, preventing unhandled exceptions and potential race conditions.
    • Updated logic to remove unnecessary conditions and streamline the promise handling.
  • Robust Video ID Extraction:
    • Enhanced the extractVideoId function by adding an additional check for null or undefined video IDs before validation. This change prevents potential errors when extracting the video ID from a malformed or incomplete URL.

Refactors

  • URL Validation:
    • Replaced the usage of ytdl.validateURL with URLUtils.validateUrl within the getVideosInfo function. This change leverages the project's utility functions for consistent URL validation and better error handling.

Summary

This set of changes aims to enhance the reliability and maintainability of the codebase, particularly in error-prone areas such as logging and URL validation

Ensure that the `extractVideoId` function checks for null or undefined `videoId` before validating it, preventing unexpected errors.
- Replaced the error thrown for invalid URLs in `getVideosInfo` with a more appropriate `URIError`.
- Updated `writeErrorLog` to reject the promise on stream error and handle finish event cleanly.
@mitsuki31 mitsuki31 added refactor Refactor and enhancement changes bugfix Fixes any issue and bug patch Patch changes labels Aug 23, 2024
@mitsuki31 mitsuki31 self-assigned this Aug 23, 2024
Copy link

codecov bot commented Aug 23, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@mitsuki31 mitsuki31 merged commit 238b15b into master Aug 23, 2024
13 of 14 checks passed
@mitsuki31 mitsuki31 deleted the fix/robust-error-handling-and-refactoring branch August 23, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Fixes any issue and bug patch Patch changes refactor Refactor and enhancement changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant