Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
20b8ffd
1
Parent(s): b88e499
Claude Code: Improve sys.path setup in error_handlers.py - add defensive path verification
Browse files- Verify .openclaw exists before adding to sys.path
- Add fallback path resolution for Docker environments
- This ensures brain_minimal imports work correctly on Cain restart
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- error_handlers.py +9 -4
error_handlers.py
CHANGED
|
@@ -17,11 +17,16 @@ from fastapi.responses import JSONResponse
|
|
| 17 |
_openclaw_package_dir = Path(__file__).parent / "openclaw"
|
| 18 |
_openclaw_internal_dir = _openclaw_package_dir / ".openclaw"
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# Add openclaw parent dir and .openclaw to sys.path for agents imports
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
if
|
| 24 |
-
|
| 25 |
|
| 26 |
|
| 27 |
async def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
|
|
|
|
| 17 |
_openclaw_package_dir = Path(__file__).parent / "openclaw"
|
| 18 |
_openclaw_internal_dir = _openclaw_package_dir / ".openclaw"
|
| 19 |
|
| 20 |
+
# Verify paths exist before adding (defensive: helps debug Docker issues)
|
| 21 |
+
if not _openclaw_internal_dir.exists():
|
| 22 |
+
# Fallback: try .openclaw directly (in case openclaw/ structure differs)
|
| 23 |
+
_openclaw_internal_dir = Path(__file__).parent / ".openclaw"
|
| 24 |
+
|
| 25 |
# Add openclaw parent dir and .openclaw to sys.path for agents imports
|
| 26 |
+
for path_dir in [_openclaw_package_dir, _openclaw_internal_dir]:
|
| 27 |
+
path_str = str(path_dir)
|
| 28 |
+
if path_str not in sys.path and path_dir.exists():
|
| 29 |
+
sys.path.insert(0, path_str)
|
| 30 |
|
| 31 |
|
| 32 |
async def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
|