fix: replace print() with logger.warning() in extensions catalog warnings - #3969
Quratulain-bilal wants to merge 2 commits into
Conversation
…ings Print statements to stderr are not appropriate for library code that may be consumed by tools or tests. Replaced with logger.warning() for proper log management. Removed unused local sys imports.
There was a problem hiding this comment.
Pull request overview
Replaces direct stderr warnings with standard Python logging in the extension catalog.
Changes:
- Added a module logger.
- Migrated two catalog warnings to
logger.warning(). - Removed unused local
sysimports.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/extensions/__init__.py |
Routes catalog warnings through logging. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (1)
src/specify_cli/extensions/init.py:3757
- Please cover the partial-fetch failure path with
caplog: make one catalog raiseExtensionError, let another succeed, and assert the named warning is logged while merging continues. This is the second logging behavior changed by the PR and currently has no regression test.
logger.warning(
"Could not fetch catalog '%s': %s", catalog_entry.name, e,
)
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
| logger.warning( | ||
| "Using non-default extension catalog. " | ||
| "Only use catalogs from sources you trust.", | ||
| file=sys.stderr, | ||
| ) |
Verify that when _fetch_single_catalog raises ExtensionError, the error is logged at WARNING level with the catalog name and error message, instead of being printed to stderr or silently swallowed.
|
Thanks — this is the right fix (stderr |
There was a problem hiding this comment.
🟡 Changes recommended
An unused import will fail Ruff CI, and one changed warning path lacks logging coverage.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
src/specify_cli/extensions/init.py:3522
- The PR changes this security warning from direct stderr output to logging, but the existing environment-variable test only checks the returned catalog entry. Add a
caplogassertion for this path so a regression back toprint()(or removal of the warning) is covered as well.
logger.warning(
"Using non-default extension catalog. "
"Only use catalogs from sources you trust.",
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
| """When a catalog fetch fails, the error must be logged at WARNING | ||
| level instead of being silently swallowed or printed to stderr.""" | ||
| import logging | ||
| from pathlib import Path |
AI Assistance DisclosureI used AI assistance (GitHub Copilot) to identify @mnriem I've added the AI disclosure above. This PR was developed with Copilot assistance to identify the print-to-logger migration points, and I personally reviewed the changes and wrote the caplog regression test. Ready for re-review when you have a chance. |
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback
Problem
print(..., file=sys.stderr) is inappropriate for library code - it bypasses the logging framework and can't be silenced or redirected by consumers.
Fix
Replaced with logger.warning() for proper log management. Removed unused local sys imports.