Skip to content

Commit

Permalink
Gracefully handle fileNotFound
Browse files Browse the repository at this point in the history
  • Loading branch information
elsell committed Feb 1, 2022
1 parent d7d461d commit 38ee284
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion MinecraftOnlinePlayersOverlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,20 @@ def _print_init(self):
)

def _save_image(self, image, image_name):
image.save(os.path.join(self._image_output_dir, image_name))
image_path = os.path.join(self._image_output_dir, image_name)

try:
if not os.path.isdir(self._image_output_dir):
os.mkdir(self._image_output_dir)

image.save(image_path)
except FileNotFoundError as e:
self._log.critical(
"Could not save image to %s! If you're attempting to save an image to a network location,"
" please ensure that the network location is accessable. Will wait and try again. (Error: %s)",
image_path,
repr(e),
)

def _build_player_image_board(self):
players = self._mcserver.get_online_players()
Expand Down

0 comments on commit 38ee284

Please sign in to comment.