Skip to content

Commit

Permalink
Minor improvement in error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AlirezaT99 committed Aug 5, 2024
1 parent 0d5d6e8 commit 21003cf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nbgrader/server_extensions/helpers/deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def _write_deadlines(self, file_path, deadlines):
except IsADirectoryError:
self.log.error("The path to file is a directory: %s", file_path)
return
except TypeError:
self.log.error("Invalid data type to write in file: %s", deadlines)
except:
self.log.error("An unexpected error occurred while writing deadlines")
return

access_mode = 0o664 if self.coursedir.groupshared else 0o644
Expand All @@ -63,6 +63,8 @@ def _write_deadlines(self, file_path, deadlines):
os.chmod(file_path, (st_mode | access_mode) & 0o777)
except PermissionError:
self.log.warning("Could not update permissions of %s", file_path)
except:
self.log.error("An unexpected error occurred while updating permissions of %s", file_path)

def _format_deadline(self, deadline):
"""Format the deadline."""
Expand All @@ -76,10 +78,13 @@ def _read_deadlines(self, file_path):

try:
entries = json.load(open(file_path, "r"))
except FileNotFoundError:
self.log.warning("No deadlines file found at {}".format(file_path))
except (FileNotFoundError, PermissionError):
self.log.warning("No deadlines file found or accessible at {}".format(file_path))
return {}
except json.JSONDecodeError:
self.log.warning("Invalid JSON in deadlines file at {}".format(file_path))
return {}
except:
self.log.error("An unexpected error occurred while loading deadlines")
return {}
return entries

0 comments on commit 21003cf

Please sign in to comment.