Skip to content

Commit 8299a87

Browse files
committed
cli(fix[error-handling]): Use logging.exception for better error reporting
why: Follow best practices for exception logging and provide better debugging info what: - Replace log.error with log.exception in exception handlers - Maintain existing debug traceback functionality - Apply to both add.py and add_from_fs.py modules
1 parent 7e17fef commit 8299a87

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/vcspull/cli/add.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def add_repo(
102102
)
103103
return
104104
except Exception:
105-
log.error(f"Error loading YAML from {config_file_path}. Aborting.")
105+
log.exception(f"Error loading YAML from {config_file_path}. Aborting.")
106106
if log.isEnabledFor(logging.DEBUG):
107107
import traceback
108108

@@ -159,7 +159,7 @@ def add_repo(
159159
f"under '{base_dir_key}'.",
160160
)
161161
except Exception:
162-
log.error(f"Error saving config to {config_file_path}")
162+
log.exception(f"Error saving config to {config_file_path}")
163163
if log.isEnabledFor(logging.DEBUG):
164164
import traceback
165165

src/vcspull/cli/add_from_fs.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def add_from_filesystem(
136136
)
137137
return
138138
except Exception:
139-
log.error(f"Error loading YAML from {config_file_path}. Aborting.")
139+
log.exception(f"Error loading YAML from {config_file_path}. Aborting.")
140140
if log.isEnabledFor(logging.DEBUG):
141141
import traceback
142142

@@ -223,7 +223,7 @@ def add_from_filesystem(
223223

224224
repos_to_add: list[tuple[str, str, str]] = []
225225
existing_repos: list[tuple[str, str, str]] = [] # (name, url, key)
226-
226+
227227
for name, url, key in found_repos:
228228
target_section = raw_config.get(key, {})
229229
if isinstance(target_section, dict) and name in target_section:
@@ -235,10 +235,13 @@ def add_from_filesystem(
235235
log.info(f"Found {len(existing_repos)} existing repositories in configuration:")
236236
for name, url, key in existing_repos:
237237
log.info(f" - {name} ({url}) at {key}{name} in {config_file_path}")
238-
238+
239239
if not repos_to_add:
240240
if existing_repos:
241-
log.info("All found repositories already exist in the configuration. Nothing to do.")
241+
log.info(
242+
"All found repositories already exist in the configuration. "
243+
"Nothing to do."
244+
)
242245
return
243246

244247
if not yes:
@@ -270,7 +273,7 @@ def add_from_filesystem(
270273
save_config_yaml(config_file_path, raw_config)
271274
log.info(f"Successfully updated {config_file_path}.")
272275
except Exception:
273-
log.error(f"Error saving config to {config_file_path}")
276+
log.exception(f"Error saving config to {config_file_path}")
274277
if log.isEnabledFor(logging.DEBUG):
275278
import traceback
276279

0 commit comments

Comments
 (0)