Add mcoplib mcoplib env doctor JSON#53
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new diagnostic script, tools/maca_env_doctor.py, designed to collect a lightweight MACA runtime environment report by gathering environment variables, checking directory paths, and executing system tools. Feedback on the changes suggests improving robustness by wrapping subprocess.run in a try...except OSError block to handle execution failures, and replacing assert statements in the self-test function with explicit conditional checks to ensure they are not compiled away under Python optimization.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| proc = subprocess.run(cmd, text=True, encoding="utf-8", errors="replace", capture_output=True) | ||
| return { | ||
| "command": cmd, | ||
| "available": True, | ||
| "stdout": proc.stdout.strip(), | ||
| "stderr": proc.stderr.strip(), | ||
| "returncode": proc.returncode, | ||
| } |
There was a problem hiding this comment.
Running external commands using subprocess.run can raise an OSError (such as PermissionError or FileNotFoundError if the executable is deleted or lacks execution permissions) even if shutil.which originally found it. To make this diagnostic tool robust and prevent the entire script from crashing, wrap the execution in a try...except OSError block and capture the error message in the output.
try:
proc = subprocess.run([executable] + cmd[1:], text=True, encoding="utf-8", errors="replace", capture_output=True)
return {
"command": cmd,
"available": True,
"stdout": proc.stdout.strip(),
"stderr": proc.stderr.strip(),
"returncode": proc.returncode,
}
except OSError as e:
return {
"command": cmd,
"available": False,
"stdout": "",
"stderr": f"Execution failed: {e}",
"returncode": None,
}| assert "tools" in data | ||
| assert "environment" in data |
There was a problem hiding this comment.
Avoid using assert statements for production code validation or control flow. When Python is run with optimization enabled (the -O flag), all assert statements are compiled away and ignored. Use explicit conditional checks and raise an appropriate exception (such as RuntimeError) instead.
| assert "tools" in data | |
| assert "environment" in data | |
| if "tools" not in data or "environment" not in data: | |
| raise RuntimeError("Self-test failed: collected data is missing expected keys.") |
Summary
Validation
Review notes