Skip to content

Commit ec184af

Browse files
committed
fix: move disk space check parsing inside try-except block
The parsing code for df output was outside the try-except block, causing uncaught exceptions to bubble up and return UNKNOWN status instead of HEALTHY or CRITICAL. Moving the parsing logic inside the try-except block ensures proper error handling and correct status reporting. Fixes test failures: - TestDiskSpaceCheck.test_disk_space_check_run - TestDiskSpaceCheck.test_disk_space_high_requirement
1 parent 490bf82 commit ec184af

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

cli/health_check.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,20 @@ def run(self) -> tuple[str, str, dict[str, Any]]:
161161
"""Check available disk space."""
162162
try:
163163
result = run_command(["df", "-B1G", "/"], timeout=2, check=True)
164+
lines = result.stdout.strip().split("\n")
165+
if len(lines) < 2:
166+
return (HealthStatus.UNKNOWN, "Could not parse disk space", {})
167+
168+
# Parse df output
169+
parts = lines[1].split()
170+
available_gb = int(parts[3].rstrip("G"))
164171
except (subprocess.SubprocessError, ValueError, IndexError, OSError) as e:
165172
return (
166173
HealthStatus.UNKNOWN,
167174
f"Failed to check disk space: {e}",
168175
{"error": str(e)},
169176
)
170177

171-
lines = result.stdout.strip().split("\n")
172-
if len(lines) < 2:
173-
return (HealthStatus.UNKNOWN, "Could not parse disk space", {})
174-
175-
# Parse df output
176-
parts = lines[1].split()
177-
available_gb = int(parts[3].rstrip("G"))
178-
179178
if available_gb >= self.min_gb:
180179
return (
181180
HealthStatus.HEALTHY,

0 commit comments

Comments
 (0)