Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 5de27a6

Browse files
authored
feat: Implement validation for taskweaver_config.json (#511)
### Description This PR addresses the `TODO` in [taskweaver/utils/app_utils.py](cci:7://file:///c:/Users/singh/OneDrive/Documents/Open%20Source/TaskWeaver/taskweaver/utils/app_utils.py:0:0-0:0) by implementing validation logic for the `taskweaver_config.json` file. ### Changes - Implemented `json.load` to verify the configuration file contains valid JSON. - Added a check to ensure the root element is a dictionary ([dict](cci:1://file:///c:/Users/singh/OneDrive/Documents/Open%20Source/TaskWeaver/taskweaver/session/session.py:357:4-362:9)), as expected for configuration files. - Added error handling for `json.JSONDecodeError` and `OSError` to prevent crashes when reading the file. ### Related Issues Resolves TODO in `taskweaver/utils/app_utils.py`
2 parents 39b1417 + e5ff7c0 commit 5de27a6

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

taskweaver/utils/app_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
from os import listdir, path
23
from typing import Optional, Tuple
34

@@ -13,7 +14,14 @@ def validate_app_config(workspace: str) -> bool:
1314
config_path = path.join(workspace, "taskweaver_config.json")
1415
if not path.exists(config_path):
1516
return False
16-
# TODO: read, parse and validate config
17+
try:
18+
with open(config_path, "r", encoding="utf-8") as f:
19+
data = json.load(f)
20+
# Config must be a dictionary (key-value pairs)
21+
if not isinstance(data, dict):
22+
return False
23+
except (json.JSONDecodeError, OSError):
24+
return False
1725
return True
1826

1927
def is_dir_valid(dir: str) -> bool:

0 commit comments

Comments
 (0)