From 8879ed0f4e36062c087a1e996fe6708cddb8c517 Mon Sep 17 00:00:00 2001 From: Sofia Willow Date: Wed, 18 Mar 2026 21:43:53 +0100 Subject: [PATCH] fix: handle missing config file gracefully (#2) The load_config() function crashed with FileNotFoundError when the config file didn't exist at ~/.config/task-cli/config.yaml. Changes: - Check if config file exists before attempting to open it - Return empty dict as default when file is missing - Catch OSError/PermissionError and warn on stderr - CLI continues to work without a config file Closes #2 --- task.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/task.py b/task.py index 53cc8ed..03982cf 100644 --- a/task.py +++ b/task.py @@ -11,11 +11,22 @@ def load_config(): - """Load configuration from file.""" + """Load configuration from file. + + Returns a dict with configuration values. If the config file does not + exist, returns default configuration instead of crashing. + """ config_path = Path.home() / ".config" / "task-cli" / "config.yaml" - # NOTE: This will crash if config doesn't exist - known bug for bounty testing - with open(config_path) as f: - return f.read() + + if not config_path.exists(): + return {} + + try: + with open(config_path) as f: + return f.read() + except (OSError, PermissionError) as e: + print(f"Warning: Could not read config file: {e}", file=sys.stderr) + return {} def main():