Spaces:
Sleeping
Sleeping
Claude Code Claude Opus 4.6 commited on
Commit ·
8a59e41
1
Parent(s): f57943a
Claude Code: Dynamic cain_status.json path resolution
Browse filesSearch common locations (/data, /app, ., /) and use first valid path found via os.path.exists(). Falls back to /data/cain_status.json if none exist.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- error_handlers.py +20 -3
error_handlers.py
CHANGED
|
@@ -58,9 +58,26 @@ async def generic_exception_handler(request: Request, exc: Exception) -> JSONRes
|
|
| 58 |
|
| 59 |
|
| 60 |
# Configuration path - cain_status.json location
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Ensure parent directory exists with proper permissions
|
| 66 |
STATUS_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
# Configuration path - cain_status.json location
|
| 61 |
+
# Dynamically search common locations for cain_status.json
|
| 62 |
+
def _resolve_status_file() -> Path:
|
| 63 |
+
"""Find cain_status.json by searching common locations."""
|
| 64 |
+
# Priority: OPENCLAW_DATA_DIR env var, then common locations
|
| 65 |
+
env_dir = os.environ.get('OPENCLAW_DATA_DIR')
|
| 66 |
+
if env_dir:
|
| 67 |
+
candidate = Path(env_dir) / "cain_status.json"
|
| 68 |
+
if candidate.exists():
|
| 69 |
+
return candidate
|
| 70 |
+
|
| 71 |
+
# Search order: /data (dataset), /app (workdir), . (current), root
|
| 72 |
+
for base in ["/data", "/app", ".", "/"]:
|
| 73 |
+
candidate = Path(base) / "cain_status.json"
|
| 74 |
+
if candidate.exists():
|
| 75 |
+
return candidate
|
| 76 |
+
|
| 77 |
+
# Default to /data/cain_status.json (will be created if needed)
|
| 78 |
+
return Path("/data/cain_status.json")
|
| 79 |
+
|
| 80 |
+
STATUS_FILE = _resolve_status_file()
|
| 81 |
|
| 82 |
# Ensure parent directory exists with proper permissions
|
| 83 |
STATUS_FILE.parent.mkdir(parents=True, exist_ok=True)
|