From 48c422e0435dd0395d7e788dd2f0752efb527199 Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Tue, 20 Jul 2021 15:11:09 -0300 Subject: [PATCH] better error message on failure --- navigator/scripts/write-chunks.py3 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/navigator/scripts/write-chunks.py3 b/navigator/scripts/write-chunks.py3 index cad06b0..6230a82 100755 --- a/navigator/scripts/write-chunks.py3 +++ b/navigator/scripts/write-chunks.py3 @@ -35,20 +35,24 @@ def write_chunk(chunk, file): if not file: path = sys.argv[1] parent_path = os.path.dirname(path) - if not os.path.exists(parent_path): - os.makedirs(parent_path, exist_ok=True) - elif os.path.isfile(parent_path): - print(parent_path + ": exists and is not a directory.") - sys.exit(1) try: + if not os.path.exists(parent_path): + os.makedirs(parent_path, exist_ok=True) + elif os.path.isfile(parent_path): + print(parent_path + ": exists and is not a directory.") + sys.exit(1) file = open(path, "wb") except Exception as e: print(e) sys.exit(1) seek = chunk["seek"] data = base64.b64decode(chunk["chunk"]) - file.seek(seek) - file.write(data) + try: + file.seek(seek) + file.write(data) + except Exception as e: + print(e) + sys.exit(1) def main(): file = None