-
Notifications
You must be signed in to change notification settings - Fork 360
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
fix: error handling for file operations #12
Conversation
could you also also do the same for pref file as well ? |
sure! |
please review, I have updated my PR accordingly! @sumanashrestha @horrormyth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff, few minor comments and test would be great, otherwise looking good 💪 🎖️
school_center.py
Outdated
|
||
logging.basicConfig(level=logging.ERROR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can just use the logger as follows. No need to use the logging module and basiconfig, we can set the default log level if needed in the future.
from logging import getLogger
logger = getLogger(__name__) `
logger.info/error("Lovely message")
school_center.py
Outdated
for row in reader: | ||
data.append(dict(row)) | ||
except FileNotFoundError as e: | ||
logging.error(f"Error: File '{file_path}' not found.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message does not need to mention "Error" as the logline itself is an error, so
logger.error(f"File '{file_path}' not found.")
would be enough, and the same for others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure that test is covered and/or added later on
👏👏 |
The original code would exit when any of the error occurs and print stack trace. 26 added lines later, it still does essentially the same thing but with some extra error message which would have been fairly obvious with the exception name. I am generally for proper error handling but just stating my observation. |
Disagreement: |
please resolve the conflicts, so that this can be merged |
The code for the function
read_tsv
andread_prefs
doesn't have explicit error handling for file operations. This modification will catch any File error operations, or IOError exceptions that occur when trying to open or read the file, and print an error message.