Skip to content

Commit 0c510c3

Browse files
dev-altclaude
andcommitted
Fix GitHub repository loading errors and enhance user feedback
Bug Fixes: - ✅ Fix lambda scoping issue causing "free variable 'e' referenced before assignment" error - ✅ Properly capture error messages before lambda callbacks - ✅ Fix both load_user_repositories and analyze_repository error handling User Experience Improvements: - ✅ Add success confirmation dialog after adding GitHub repository - ✅ Auto-select newly added repository for immediate use - ✅ Validate repository exists before adding with real-time GitHub API check - ✅ Enhanced error messages with helpful examples and guidance - ✅ Support .git URL suffixes and various GitHub URL formats - ✅ Show repository description in validation confirmation Technical Enhancements: - Better URL parsing and validation - Improved GitHub API error handling (404 vs other errors) - Pass github_client to dialog for repository validation - More informative error messages for debugging The GitHub functionality should now work reliably without crashes! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 715a40a commit 0c510c3

1 file changed

Lines changed: 55 additions & 12 deletions

File tree

src/gui.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,19 @@ def add_github_repository(self):
400400
repo_item = RepositoryItem(repo_name, "", repo_url, "github")
401401
self.repositories.append(repo_item)
402402
self.update_repository_list()
403+
404+
# Show success feedback
405+
messagebox.showinfo("Repository Added",
406+
f"Successfully added GitHub repository:\n{repo_name}\n\nYou can now select it and click 'Analyze Repository' to get detailed analysis.")
407+
408+
# Select the newly added repository
409+
for item in self.repo_tree.get_children():
410+
if self.repo_tree.item(item)['text'].endswith(repo_name.split('/')[-1]):
411+
self.repo_tree.selection_set(item)
412+
self.repo_tree.see(item)
413+
self.on_repository_select(None) # Update info panel
414+
break
415+
403416
self.logger.info(f"Added GitHub repository: {repo_name}", "GUI")
404417

405418
def load_user_repositories(self):
@@ -434,7 +447,8 @@ def load_repos_thread():
434447
self.root.after(0, lambda: self._finish_load_repos(loading_dialog, len(repos)))
435448

436449
except Exception as e:
437-
self.root.after(0, lambda: self._handle_load_repos_error(loading_dialog, str(e)))
450+
error_msg = str(e) # Capture the error message
451+
self.root.after(0, lambda: self._handle_load_repos_error(loading_dialog, error_msg))
438452

439453
# Start loading in background thread
440454
threading.Thread(target=load_repos_thread, daemon=True).start()
@@ -594,8 +608,9 @@ def _analyze_repository_thread(self, repo_item: RepositoryItem):
594608

595609
except Exception as e:
596610
repo_item.status = "error"
611+
error_msg = str(e) # Capture the error message
597612
self.logger.error(f"Repository analysis failed: {e}", "ANALYSIS", e)
598-
self.root.after(0, lambda: self._update_analysis_ui(repo_item, "error", str(e)))
613+
self.root.after(0, lambda: self._update_analysis_ui(repo_item, "error", error_msg))
599614

600615
finally:
601616
self.is_analyzing = False
@@ -1111,6 +1126,7 @@ class GitHubRepoDialog:
11111126

11121127
def __init__(self, parent, github_client):
11131128
self.result = None
1129+
self.github_client = github_client
11141130

11151131
# Create dialog
11161132
self.dialog = tk.Toplevel(parent)
@@ -1152,22 +1168,49 @@ def on_add(self):
11521168
messagebox.showerror("Invalid URL", "Please enter a repository URL.")
11531169
return
11541170

1171+
# Validate GitHub URL format
1172+
if 'github.com' not in url:
1173+
messagebox.showerror("Invalid URL", "Please enter a valid GitHub repository URL.\nExample: https://github.com/username/repository")
1174+
return
1175+
11551176
# Parse repository name from URL
11561177
try:
1157-
if 'github.com' in url:
1158-
parts = url.rstrip('/').split('/')
1159-
if len(parts) >= 2:
1160-
repo_name = f"{parts[-2]}/{parts[-1]}"
1161-
else:
1162-
repo_name = parts[-1]
1163-
else:
1164-
repo_name = url.split('/')[-1]
1178+
parts = url.rstrip('/').split('/')
1179+
if len(parts) < 2:
1180+
raise ValueError("Invalid URL format")
1181+
1182+
owner = parts[-2]
1183+
repo = parts[-1]
1184+
1185+
# Remove .git if present
1186+
if repo.endswith('.git'):
1187+
repo = repo[:-4]
1188+
1189+
repo_name = f"{owner}/{repo}"
1190+
1191+
# Test if repository exists (if github_client is available)
1192+
if hasattr(self, 'github_client') and self.github_client:
1193+
try:
1194+
test_repo = self.github_client.get_repo(repo_name)
1195+
# If we get here, repo exists
1196+
messagebox.showinfo("Repository Found",
1197+
f"✅ Repository found: {test_repo.full_name}\n{test_repo.description or 'No description'}")
1198+
except Exception as e:
1199+
if "404" in str(e):
1200+
messagebox.showerror("Repository Not Found",
1201+
f"❌ Repository '{repo_name}' not found or is private.\nPlease check the URL and try again.")
1202+
return
1203+
else:
1204+
# Other API error, but let's continue anyway
1205+
messagebox.showwarning("Validation Warning",
1206+
f"⚠️ Could not validate repository '{repo_name}'.\nProceeding anyway...")
11651207

11661208
self.result = (repo_name, url)
11671209
self.dialog.destroy()
11681210

1169-
except Exception:
1170-
messagebox.showerror("Invalid URL", "Please enter a valid GitHub repository URL.")
1211+
except Exception as e:
1212+
messagebox.showerror("Invalid URL",
1213+
f"Please enter a valid GitHub repository URL.\nError: {str(e)}\n\nExample: https://github.com/username/repository")
11711214

11721215
def on_cancel(self):
11731216
"""Handle cancel button click."""

0 commit comments

Comments
 (0)