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

fix: error handling for file operations #12

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

trishan9
Copy link
Contributor

@trishan9 trishan9 commented Apr 20, 2024

The code for the function read_tsv and read_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.

@sumanashrestha
Copy link
Collaborator

could you also also do the same for pref file as well ?

school_center.py Outdated Show resolved Hide resolved
@trishan9
Copy link
Contributor Author

could you also also do the same for pref file as well ?

sure!

@trishan9
Copy link
Contributor Author

please review, I have updated my PR accordingly! @sumanashrestha @horrormyth

Copy link
Contributor

@horrormyth horrormyth left a 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)
Copy link
Contributor

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.")
Copy link
Contributor

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.

school_center.py Show resolved Hide resolved
Copy link
Contributor

@horrormyth horrormyth left a 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

@rajan-poudel
Copy link

👏👏

@sapradhan
Copy link
Collaborator

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.

@horrormyth
Copy link
Contributor

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:
The client/user is not capable of dissecting the exception traceback, those are only for developers who can understand them. So, in any client use case, throwing exceptions to them is a bad idea. The user should be informed nicely about what went wrong regardless of how miserably the system failed. Here, the message is nicely written, and the user will know what went wrong.

@sumanashrestha
Copy link
Collaborator

please resolve the conflicts, so that this can be merged

@sumanashrestha sumanashrestha merged commit 49e1aec into moest-np:main Apr 24, 2024
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.

None yet

5 participants