Skip to content

Fix: Use FileNotFoundError for file not found in main.py#558

Closed
creepereye1204 wants to merge 1 commit intotheskumar:mainfrom
creepereye1204:main
Closed

Fix: Use FileNotFoundError for file not found in main.py#558
creepereye1204 wants to merge 1 commit intotheskumar:mainfrom
creepereye1204:main

Conversation

@creepereye1204
Copy link

Replaced IOError with FileNotFoundError on line 320 of main.py to use a more specific and appropriate exception for file not found errors.

@creepereye1204
Copy link
Author

creepereye1204 commented Apr 24, 2025

Title: Refactor: Improve error handling and remove unused parameter in main.py

Description:

This pull request introduces two refactoring changes to main.py aimed at improving code clarity and maintainability.

  1. Use Specific Exception for File Not Found:
    The code previously raised a general IOError when a file was not found. This has been updated to raise the more specific FileNotFoundError. This change provides clearer error information to callers and allows for more precise error handling.

    Before (approx. line 319):

    if raise_error_if_not_found:
        raise IOError("File not found")
    return ""

    After:

    if raise_error_if_not_found:
        raise FileNotFoundError("File not found")
    return ""

@bbc2
Copy link
Collaborator

bbc2 commented Jan 10, 2026

This looks good to me but I would like to update the test test_find_dotenv_no_file_raise to reflect this change and squash the commits before rebasing and merging to clean up the git history. It looks like I can't do it myself in this PR, so I might do it in another PR if necessary.

Replaced IOError with FileNotFoundError on line 377 of main.py to use a more specific and appropriate exception for file not found errors.

test: update test_find_dotenv_no_file_raise to expect FileNotFoundError
Updated test_main.py (line 351) to replace IOError with FileNotFoundError so that the test matches the updated exception handling in main.py.
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.

2 participants