mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 14:06:15 +08:00
chore: set logging level to debug when reading YAML files and falling back to default value in case of None (#6758)
This commit is contained in:
parent
f43e27814c
commit
cb01bf2986
@ -12,7 +12,7 @@ def load_yaml_file(file_path: str, ignore_error: bool = True, default_value: Any
|
|||||||
Safe loading a YAML file
|
Safe loading a YAML file
|
||||||
:param file_path: the path of the YAML file
|
:param file_path: the path of the YAML file
|
||||||
:param ignore_error:
|
:param ignore_error:
|
||||||
if True, return default_value if error occurs and the error will be logged in warning level
|
if True, return default_value if error occurs and the error will be logged in debug level
|
||||||
if False, raise error if error occurs
|
if False, raise error if error occurs
|
||||||
:param default_value: the value returned when errors ignored
|
:param default_value: the value returned when errors ignored
|
||||||
:return: an object of the YAML content
|
:return: an object of the YAML content
|
||||||
@ -20,12 +20,13 @@ def load_yaml_file(file_path: str, ignore_error: bool = True, default_value: Any
|
|||||||
try:
|
try:
|
||||||
with open(file_path, encoding='utf-8') as yaml_file:
|
with open(file_path, encoding='utf-8') as yaml_file:
|
||||||
try:
|
try:
|
||||||
return yaml.safe_load(yaml_file)
|
yaml_content = yaml.safe_load(yaml_file)
|
||||||
|
return yaml_content if yaml_content else default_value
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise YAMLError(f'Failed to load YAML file {file_path}: {e}')
|
raise YAMLError(f'Failed to load YAML file {file_path}: {e}')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if ignore_error:
|
if ignore_error:
|
||||||
logger.warning(f'Failed to load YAML file {file_path}: {e}')
|
logger.debug(f'Failed to load YAML file {file_path}: {e}')
|
||||||
return default_value
|
return default_value
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user