Skip to content

Commit bd44307

Browse files
committed
Fix FileDirValue to validate input before setting value
- Add input validation before assigning to self.value - Validate that input is a string and not empty - Only set self.value after successful directory creation and validation - Addresses requirement to validate all values before they get set
1 parent 78f6750 commit bd44307

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

Granny/Models/Values/FileDirValue.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ def setValue(self, value: str):
2525
Raises:
2626
ValueError: If the path is not a valid directory after assignment.
2727
"""
28-
self.value = value
29-
if not self.validate():
28+
# Validate input before setting
29+
if not isinstance(value, str):
30+
raise ValueError(f"Directory path must be a string, got {type(value)}")
31+
if not value.strip():
32+
raise ValueError("Directory path cannot be empty")
33+
34+
# Create directory first, then set and validate
35+
os.makedirs(value, exist_ok=True)
36+
37+
# Only set the value after successful directory creation and validation
38+
if os.path.isdir(value):
39+
self.value = value
40+
else:
3041
raise ValueError("Not a directory. Please specify a directory.")
31-
os.makedirs(self.value, exist_ok=True)
3242

3343
def validate(self) -> bool:
3444
"""

0 commit comments

Comments
 (0)