-
Notifications
You must be signed in to change notification settings - Fork 1
fix(CODEWIKI-005): CU-86akhf8u6 8 review findings across 4 files #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5f933d7
e38c009
67c0f3f
468ea6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,8 +106,8 @@ def clone_repository(github_url: str) -> str: | |
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| except: | ||
| pass | ||
| except Exception as e: | ||
| logger.debug(f"Non-fatal git config step failed: {e}") | ||
|
|
||
| subprocess.run( | ||
| [ | ||
|
Comment on lines
106
to
113
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π clone_repository leaves temp_dir undeleted if the git executable check runs after mkdtemp but the initial 'longpaths' config subprocess.run raises an untyped exception Added a final π€ Prompt for AI agentsfix confidence: π΄ 55 low β review closely β react π/π to teach the reviewer |
||
|
|
@@ -158,8 +158,8 @@ def clone_repository(github_url: str) -> str: | |
| capture_output=True, | ||
| text=True, | ||
| ) | ||
| except: | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π Second bare except swallowing sparse-checkout setup errors without logging In π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
| pass | ||
| except Exception as e: | ||
| logger.debug(f"Non-fatal sparse-checkout setup failed: {e}") | ||
| return temp_dir | ||
| except subprocess.TimeoutExpired: | ||
| if os.path.exists(temp_dir): | ||
|
|
@@ -178,6 +178,10 @@ def clone_repository(github_url: str) -> str: | |
| f"Git executable not found at '{GIT_EXECUTABLE_PATH}'. " | ||
| "Please ensure Git is installed and the path is correct." | ||
| ) | ||
| except Exception: | ||
| if os.path.exists(temp_dir): | ||
| cleanup_repository_safe(temp_dir) | ||
| raise | ||
|
|
||
|
|
||
| def cleanup_repository_safe(repo_dir: str) -> bool: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| FastAPI route handlers for the CodeWiki web application. | ||
| """ | ||
|
|
||
| import logging | ||
| import re | ||
| from datetime import datetime, timedelta | ||
| from pathlib import Path | ||
|
Comment on lines
3
to
9
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π codewiki/src/fe/routes.py never defines a module-level logger despite catching/discarding exceptions Added π€ Prompt for AI agentsfix confidence: π’ 95 high β react π/π to teach the reviewer |
||
|
|
@@ -22,6 +23,8 @@ | |
| from .config import WebAppConfig | ||
| from codewiki.src.utils import file_manager | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class WebRoutes: | ||
| """Handles all web routes for the application.""" | ||
|
|
@@ -132,6 +135,7 @@ async def index_post(self, request: Request, repo_url: str = Form(...), commit_i | |
| repo_url = "" # Clear form | ||
|
|
||
| except Exception as e: | ||
| logger.exception("Failed to add repository %s to queue", normalized_repo_url) | ||
| message = f"Failed to add repository to queue: {str(e)}\n{format_exc()}" | ||
| message_type = "error" | ||
|
|
||
|
|
@@ -182,6 +186,9 @@ async def serve_generated_docs(self, job_id: str, filename: str = "overview.md") | |
| if not re.match(r'^[A-Za-z0-9_.-]+$', job_id): | ||
| raise HTTPException(status_code=400, detail="Invalid job ID") | ||
|
|
||
| if '..' in filename: | ||
| raise HTTPException(status_code=400, detail="Invalid file path") | ||
|
|
||
| job = self.background_worker.get_job_status(job_id) | ||
| docs_path = None | ||
| repo_url = None | ||
|
|
@@ -230,7 +237,7 @@ async def serve_generated_docs(self, job_id: str, filename: str = "overview.md") | |
| try: | ||
| module_tree = file_manager.load_json(module_tree_file) | ||
| except Exception: | ||
| pass | ||
| logger.exception("Failed to load module tree from %s", module_tree_file) | ||
|
|
||
| # Load metadata | ||
| metadata = None | ||
|
Comment on lines
237
to
243
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π routes.py uses bare except-pass blocks that silently discard failures instead of logging via module logger Replaced the silent π€ Prompt for AI agentsfix confidence: π‘ 85 medium β react π/π to teach the reviewer |
||
|
|
@@ -239,12 +246,12 @@ async def serve_generated_docs(self, job_id: str, filename: str = "overview.md") | |
| try: | ||
| metadata = file_manager.load_json(metadata_file) | ||
| except Exception: | ||
| pass | ||
| logger.exception("Failed to load metadata from %s", metadata_file) | ||
|
|
||
| # Serve the requested file | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π serve_generated_docs constructs docs_path before validating job_id format, unlike serve_doc's stricter directory-traversal guard In π€ Prompt for AI agentsfix confidence: π‘ 60 medium β react π/π to teach the reviewer |
||
| docs_path_resolved = docs_path.resolve() | ||
| file_path = (docs_path / filename).resolve() | ||
| if docs_path_resolved != file_path and docs_path_resolved not in file_path.parents: | ||
| if not file_path.is_relative_to(docs_path_resolved): | ||
| raise HTTPException(status_code=400, detail="Invalid file path") | ||
| if not file_path.exists(): | ||
| raise HTTPException(status_code=404, detail=f"File {filename} not found") | ||
|
|
@@ -272,6 +279,7 @@ async def serve_generated_docs(self, job_id: str, filename: str = "overview.md") | |
| return HTMLResponse(content=render_template(DOCS_VIEW_TEMPLATE, context)) | ||
|
|
||
| except Exception as e: | ||
| logger.exception("Error reading %s", filename) | ||
| raise HTTPException(status_code=500, detail=f"Error reading {filename}: {e}\n{format_exc()}") | ||
|
|
||
| def _normalize_github_url(self, url: str) -> str: | ||
|
|
@@ -281,6 +289,7 @@ def _normalize_github_url(self, url: str) -> str: | |
| repo_info = GitHubRepoProcessor.get_repo_info(url) | ||
| return f"https://github.com/{repo_info['full_name']}" | ||
| except Exception: | ||
| logger.exception("Failed to normalize GitHub URL %s, falling back to basic normalization", url) | ||
| # Fallback to basic normalization | ||
| return url.rstrip('/').lower() | ||
|
|
||
|
|
@@ -304,3 +313,4 @@ def cleanup_old_jobs(self): | |
| for job_id in expired_jobs: | ||
| if job_id in self.background_worker.job_status: | ||
| del self.background_worker.job_status[job_id] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| from fastapi import FastAPI, Request, Form | ||
| from fastapi.responses import HTMLResponse | ||
|
|
||
|
|
@@ -20,6 +21,8 @@ | |
| from .config import WebAppConfig | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # Initialize FastAPI app | ||
| app = FastAPI( | ||
| title="CodeWiki", | ||
|
|
@@ -110,11 +113,11 @@ def main(): | |
| # Start background worker | ||
| background_worker.start() | ||
|
|
||
| print(f"π CodeWiki Web Application starting...") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π web_app.py main() uses print() instead of module logger for server startup diagnostics Replaced all five print() calls in main() (startup banner, server URL, cache dir, temp dir, and the "Press Ctrl+C" hint) with logger.info() calls on a module-level logger created via π€ Prompt for AI agentsfix confidence: π’ 90 high β react π/π to teach the reviewer |
||
| print(f"π Server running at: http://{args.host}:{args.port}") | ||
| print(f"π Cache directory: {WebAppConfig.get_absolute_path(WebAppConfig.CACHE_DIR)}") | ||
| print(f"ποΈ Temp directory: {WebAppConfig.get_absolute_path(WebAppConfig.TEMP_DIR)}") | ||
| print("\nPress Ctrl+C to stop the server") | ||
| logger.info("π CodeWiki Web Application starting...") | ||
| logger.info(f"π Server running at: http://{args.host}:{args.port}") | ||
| logger.info(f"π Cache directory: {WebAppConfig.get_absolute_path(WebAppConfig.CACHE_DIR)}") | ||
| logger.info(f"ποΈ Temp directory: {WebAppConfig.get_absolute_path(WebAppConfig.TEMP_DIR)}") | ||
| logger.info("Press Ctrl+C to stop the server") | ||
|
|
||
| try: | ||
| uvicorn.run( | ||
|
|
@@ -125,9 +128,9 @@ def main(): | |
| log_level="debug" if args.debug else "info" | ||
| ) | ||
| except KeyboardInterrupt: | ||
| print("\nπ Server stopped") | ||
| logger.info("π Server stopped") | ||
| background_worker.stop() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,13 @@ | |
|
|
||
| import os, sys, logging | ||
|
|
||
| # Setup logging | ||
| logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s', force=True) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 𦩠π logging.basicConfig() called directly in a standalone script instead of using centralized setup_logging Replaced the direct π€ Prompt for AI agentsfix confidence: π΄ 55 low β review closely β react π/π to teach the reviewer |
||
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
|
|
||
| from codewiki.src.be.dependency_analyzer.utils.logging_config import setup_logging | ||
|
|
||
| # Setup logging | ||
| setup_logging(level=logging.INFO, format='[%(levelname)s] %(message)s', force=True) | ||
|
|
||
| from dotenv import load_dotenv | ||
| load_dotenv('.env.local') | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
𦩠π Bare except clauses in cloning.py swallow errors without any logging
In
clone_repository, the bareexcept: passaround thecore.longpathsgit config subprocess call was changed toexcept Exception as e: logger.debug(f"Non-fatal git config step failed: {e}"), giving debug-level trace of any failure per CODEWIKI-005.π€ Prompt for AI agents
fix confidence: π’ 90 high β react π/π to teach the reviewer