Sergio00166/webFILE

bad-smells correction

Closed this issue · 2 comments

actions.py

Error Handling: Added try-except blocks in all functions to catch and report errors. This helps in preventing the program from crashing and provides useful error messages for debugging.

sort_contents: Catches KeyError and general Exception.
isornot: Catches general Exception.
filepage_func: Catches general Exception.
index_func: Catches general Exception.
sub_cache_handler: Catches general Exception.
Improved Path Handling:

Replaced concatenation with sep by using os.path.join for better compatibility and readability.
File Handling:

Used with open for file operations to ensure files are properly closed after operations, preventing potential file handling errors.
Circular List Access:

Replaced direct list indexing with modulo operation in filepage_func to handle circular list access safely.
Exception Messages:

Added detailed error messages in the except blocks to provide context about the errors.
File Removal Error Handling:

Handled potential OSError during file removal in sub_cache_handler.

functions.py

Error Handling: Added try-except blocks to all functions to catch and report errors, preventing the program from crashing and providing useful error messages for debugging.

⦁ sort_results: Added error handling.
⦁ readable: Added error handling.
⦁ unreadable: Added error handling.
⦁ unreadable_date: Added error handling.
⦁ get_file_type: Added error handling.
⦁ is_subdirectory: Added error handling.
⦁ get_directory_size: Added error handling.
⦁ get_folder_content: Improved existing error handling.
Path Handling:

⦁ Used os.path.join and os.path.relpath consistently for better compatibility and readability.
File Handling:

⦁ Used with open for file operations to ensure files are properly closed after operations, preventing potential file handling errors.
Exception Messages:

⦁ Added detailed error messages in the except blocks to provide context about the errors.

main.py

Error Handling:
Enhanced error handling in each route to provide more detailed information about exceptions.
Logging:
Added logging to capture detailed error messages for debugging purposes.
Path Handling:
Ensured consistent and safe handling of paths using os.path.join.

subtitles.py

⦁ Error Handling: Enhanced error handling in the functions to ensure the script fails gracefully and provides meaningful error messages.
⦁ Logging: Added logging to capture error messages for debugging purposes.
⦁ Resource Management: Used context managers (with statements) for file operations to ensure files are properly closed.

start.py

Error Handling: Enhanced error handling to ensure the script fails gracefully and provides meaningful error messages.
Logging: Added logging to capture error messages for debugging purposes.
Resource Management: Used context managers (with statements) for file operations to ensure files are properly closed.
Refactoring: Cleaned up the code for readability and maintainability.

Yes it can be useful for better logging of the errors in the console, but one thing you are wrong is that currently the program does not break, on the main.py it catches everything and returs an error code to the user.
Another thing is why this in on the issues page. Because you writed changes to the code and as i see it shoud be a pull request instead of a issues page.

I saw you fork and you have some errors, one error is my fault because I did not comment correctly the code and secondly you dont need to return nothing after raising an Error because that function breaks ands returns to the function that called it.

Also I dont like the idea to write the logs to a file, and if implemented should be optional and have an arg with the path of the log.

I have added a simpler version that for all the errors than can happen on the server code, ignores the exception and prints the file and the line and a description of the error, for the 404 and 403 (FileNotFoundError and PermissionError) the return status and the request is enough to know what recourse cant be accesed.