Skip to content

Commit 5535cf0

Browse files
author
Julian Vanden Broeck
committed
Use SettingsErrors when file can't be used as source
Some file formats (at least yaml) allow to represent non dictionnary values. In such situation we can't add the values read from those files. Instead of raising a ValueError, we now raise a SettingsError and indicate we can't parse the related config file.
1 parent f3a25f2 commit 5535cf0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pydantic_settings/sources.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,10 @@ def _read_files(self, files: PathType | None) -> dict[str, Any]:
19121912
for file in files:
19131913
file_path = Path(file).expanduser()
19141914
if file_path.is_file():
1915-
vars.update(self._read_file(file_path))
1915+
try:
1916+
vars.update(self._read_file(file_path))
1917+
except ValueError as e:
1918+
raise SettingsError(f'Parsing error encountered for {file_path}: {e}')
19161919
return vars
19171920

19181921
@abstractmethod

0 commit comments

Comments
 (0)