X Tutup
Skip to content

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

Open
creepereye1204 wants to merge 2 commits intotheskumar:mainfrom
Text-Neck-Hub:main
Open

Replaced IOError with FileNotFoundError on line 320 of main.py to use a more specific and appropriate exception for file not found errors.#626
creepereye1204 wants to merge 2 commits intotheskumar:mainfrom
Text-Neck-Hub:main

Conversation

@creepereye1204
Copy link

Title: 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.

Changes

  • Use specific exception for file not found
    Replace raising a general IOError with the more specific FileNotFoundError when a dotenv file is not found. This provides clearer error information and enables more precise exception handling by callers.

    Before (approx. line 377):

    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 ""
  • Remove unused parameter in main.py
    Remove the unused parameter to reduce confusion and improve function signatures. (Include the exact parameter name and small code diff in the commit if needed.)

Tests updated

  • Update tests to expect the new exception type. In tests/test_main.py at line 349, change the assertion from expecting IOError to expecting FileNotFoundError.

    Before:

    with pytest.raises(IOError):
        dotenv.find_dotenv(raise_error_if_not_found=True, usecwd=True)

    After:

    with pytest.raises(FileNotFoundError):
        dotenv.find_dotenv(raise_error_if_not_found=True, usecwd=True)

…r Updated test_main.py (line 351) to replace IOError with FileNotFoundError so that the test matches the updated exception handling in main.py.
…rror with FileNotFoundError on line 377 of main.py to use a more specific and appropriate exception for file not found errors.
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.

1 participant

X Tutup