Skip to content

Commit 723947c

Browse files
author
Brett Chaldecott
committed
fix: improve error handling in config_loader.py
- Add try-catch block to handle file operations - Provide specific error messages for FileNotFoundError - Handle YAML and JSON parsing errors with descriptive messages - Replace elif with if for better readability
1 parent 58d2f7f commit 723947c

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

kinde_sdk/auth/config_loader.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ def load_config(file_path: str) -> Dict[str, Any]:
1313
Returns:
1414
Dict[str, Any]: Configuration dictionary.
1515
"""
16-
with open(file_path, "r") as file:
17-
if file_path.endswith(".yaml") or file_path.endswith(".yml"):
18-
return yaml.safe_load(file)
19-
elif file_path.endswith(".json"):
20-
return json.load(file)
21-
else:
22-
raise ValueError("Unsupported file format. Use YAML or JSON.")
16+
try:
17+
with open(file_path, "r") as file:
18+
if file_path.endswith(".yaml") or file_path.endswith(".yml"):
19+
return yaml.safe_load(file)
20+
if file_path.endswith(".json"):
21+
return json.load(file)
22+
raise ValueError("Unsupported file format. Use YAML or JSON.")
23+
except FileNotFoundError:
24+
raise FileNotFoundError(f"Configuration file not found: {file_path}")
25+
except (yaml.YAMLError, json.JSONDecodeError) as e:
26+
raise ValueError(f"Error parsing configuration file: {e}")

0 commit comments

Comments
 (0)