Skip to content

Commit 0885d22

Browse files
committed
tests: Handling potential errors gracefully
Handling potential errors gracefully at exa-receive.py Signed-off-by: y-bharath14 <[email protected]>
1 parent 44c4743 commit 0885d22

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tests/topotests/lib/exa-receive.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,23 @@
1919
parser.add_argument("peer", type=int, help="The peer number")
2020
args = parser.parse_args()
2121

22-
savepath = os.path.join(args.logdir, "peer{}-received.log".format(args.peer))
23-
routesavefile = open(savepath, "w")
22+
# Ensure log directory exists
23+
logdir = args.logdir
24+
if not os.path.exists(logdir):
25+
try:
26+
# Create a new log directory
27+
os.makedirs(logdir)
28+
except OSError as e:
29+
print(f"Error in creating log directory: {e}")
30+
exit(1)
31+
32+
savepath = os.path.join(logdir, f"peer{args.peer}-received.log")
33+
34+
try:
35+
routesavefile = open(savepath, "w")
36+
except IOError as e:
37+
print(f"Error in opening log file: {e}")
38+
exit(1)
2439

2540
while True:
2641
try:

0 commit comments

Comments
 (0)