fix: Use context manager for file reading in load_user

Ensures proper resource cleanup by using 'with' statement instead of
bare open() call when reading user profile files.
This commit is contained in:
oobabooga 2026-01-14 19:39:08 -03:00
parent 212a88a6f5
commit 09a604d47b

View file

@ -1683,7 +1683,9 @@ def load_user(user_name, name1, user_bio):
logger.error(f"Could not find the user \"{user_name}\" inside user_data/users. No user has been loaded.")
raise ValueError
file_contents = open(filepath, 'r', encoding='utf-8').read()
with open(filepath, 'r', encoding='utf-8') as f:
file_contents = f.read()
extension = filepath.suffix[1:] # Remove the leading dot
data = json.loads(file_contents) if extension == "json" else yaml.safe_load(file_contents)