Skip to content

Commit dbdb131

Browse files
committed
Narrow exception handling in load_yaml_file
Replace the broad except Exception with specific catches for yaml.YAMLError, AnsibleError (vault decryption), and OSError (file I/O). Unexpected exceptions now propagate to the caller, which is the Pythonic convention -- all callers already have their own except Exception safety nets with context-appropriate messages. AI-assisted: Claude Code Signed-off-by: Roger Luethi <luethi@osism.tech>
1 parent 9d25b3e commit dbdb131

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

osism/tasks/conductor/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44

55
from ansible import constants as ansible_constants
6+
from ansible.errors import AnsibleError
67
from ansible.parsing.vault import VaultLib, VaultSecret
78
from loguru import logger
89

@@ -112,8 +113,11 @@ def load_yaml_file(path):
112113
except yaml.YAMLError as exc:
113114
logger.debug(f"Failed to parse YAML file {path}: {exc}")
114115
return None
115-
except Exception as exc:
116-
logger.debug(f"Failed to load YAML file {path}: {exc}")
116+
except AnsibleError as exc:
117+
logger.debug(f"Failed to decrypt YAML file {path}: {exc}")
118+
return None
119+
except OSError as exc:
120+
logger.debug(f"Failed to read YAML file {path}: {exc}")
117121
return None
118122

119123

0 commit comments

Comments
 (0)