Skip to content

Commit 2faf781

Browse files
Valkyrie00amartyasinha
authored andcommitted
[pcp_metrics] improve exception handling in plot.py annotate function
Move datetime.strptime() call inside try/except block to properly catch parsing errors. Also add TypeError to handled exceptions for robustness against unexpected input types. Signed-off-by: Vito Castellano <vcastell@redhat.com>
1 parent 9ecdab2 commit 2faf781

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

roles/pcp_metrics/files/plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ def annotate(axs: Iterable[plt.Axes]) -> None:
412412
for annotation in data:
413413
try:
414414
time, details = annotation.split(" | ", maxsplit=1)
415-
except ValueError:
415+
time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S,%f")
416+
except (ValueError, TypeError):
416417
print("WARNING Skipping malformed annotation line:", annotation.strip())
417418
continue
418-
time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S,%f")
419419

420420
if details.startswith("PLAY"):
421421
color = "darkred"

0 commit comments

Comments
 (0)