From: Y Bharath Date: Mon, 24 Mar 2025 07:43:22 +0000 (+0530) Subject: tests: Handling potential errors gracefully X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=0885d2232c4a253f29970f58336de610991f0cd4;p=matthieu%2Ffrr.git tests: Handling potential errors gracefully Handling potential errors gracefully at exa-receive.py Signed-off-by: y-bharath14 --- diff --git a/tests/topotests/lib/exa-receive.py b/tests/topotests/lib/exa-receive.py index 2ea3a75a5f..9035b6ab15 100755 --- a/tests/topotests/lib/exa-receive.py +++ b/tests/topotests/lib/exa-receive.py @@ -19,8 +19,23 @@ parser.add_argument( parser.add_argument("peer", type=int, help="The peer number") args = parser.parse_args() -savepath = os.path.join(args.logdir, "peer{}-received.log".format(args.peer)) -routesavefile = open(savepath, "w") +# Ensure log directory exists +logdir = args.logdir +if not os.path.exists(logdir): + try: + # Create a new log directory + os.makedirs(logdir) + except OSError as e: + print(f"Error in creating log directory: {e}") + exit(1) + +savepath = os.path.join(logdir, f"peer{args.peer}-received.log") + +try: + routesavefile = open(savepath, "w") +except IOError as e: + print(f"Error in opening log file: {e}") + exit(1) while True: try: