Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Granny/Models/Values/FileDirValue.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,20 @@ def setValue(self, value: str):
Raises:
ValueError: If the path is not a valid directory after assignment.
"""
self.value = value
if not self.validate():
# Validate input before setting
if not isinstance(value, str):
raise ValueError(f"Directory path must be a string, got {type(value)}")
if not value.strip():
raise ValueError("Directory path cannot be empty")

# Create directory first, then set and validate
os.makedirs(value, exist_ok=True)

# Only set the value after successful directory creation and validation
if os.path.isdir(value):
self.value = value
else:
raise ValueError("Not a directory. Please specify a directory.")
os.makedirs(self.value, exist_ok=True)

def validate(self) -> bool:
"""
Expand Down