Skip to content

Create, Evaluate, and Connect AI Skills

Enhance download error handling

LiamLYYYca90ab62062c
diff --git a/skillnet-ai/pyproject.toml b/skillnet-ai/pyproject.toml
index ca48621..2cef2dd 100644
--- a/skillnet-ai/pyproject.toml
+++ b/skillnet-ai/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "skillnet-ai"
-version = "0.0.14"
+version = "0.0.15"
description = "Official Python SDK for SkillNet: Create, Evaluate, and Connect AI Skills."
readme = "README.md"
authors = [{ name = "SkillNet Team", email = "[email protected]" }]
diff --git a/skillnet-ai/src/skillnet_ai/cli.py b/skillnet-ai/src/skillnet_ai/cli.py
index 840d4c2..38e7f26 100644
--- a/skillnet-ai/src/skillnet_ai/cli.py
+++ b/skillnet-ai/src/skillnet_ai/cli.py
@@ -6,7 +6,7 @@ from rich.table import Table
from rich.panel import Panel
from rich.columns import Columns
from skillnet_ai.creator import SkillCreator
-from skillnet_ai.downloader import SkillDownloader
+from skillnet_ai.downloader import SkillDownloader, GitHubAPIError
from skillnet_ai.evaluator import SkillEvaluator, EvaluatorConfig
from skillnet_ai.searcher import SkillNetSearcher
from skillnet_ai.analyzer import SkillRelationshipAnalyzer
@@ -148,16 +148,24 @@ def download(
console.print(table)
console.print(f"\n[green]✅ {folder_name} is ready to use.[/green]")
else:
- # Failure (Logic handled inside class, but we catch the None return)
- console.print("[bold red]❌ Download Failed.[/bold red]")
- console.print("Possible reasons:")
- console.print("1. Please check your network settings and ensure connection to GitHub is working properly.")
- console.print("2. The URL format is incorrect (must point to a specific skill folder, not just the repo root).")
- console.print("3. The repository is private and no token was provided.")
- console.print("4. GitHub API rate limits exceeded (try providing a token).")
+ # Generic Failure (e.g., no files found, URL invalid)
+ console.print("[bold red]❌ Download Failed: Could not process the files.[/bold red]")
raise typer.Exit(code=1)
+ except GitHubAPIError as e:
+ # 4. Handle Specific GitHub API Errors with actionable UI feedback
+ console.print(f"[bold red]❌ GitHub API Error [{e.status_code}]:[/bold red] {e.message}")
+
+ # Provide smart hints based on the status code
+ if e.status_code == 403:
+ console.print("\n[yellow]💡 Tip: You may have hit the GitHub API rate limit. Please provide a GitHub Personal Access Token (using the --token flag).[/yellow]")
+ elif e.status_code == 404:
+ console.print("\n[yellow]💡 Tip: The path does not exist, or this is a private repository (requires a --token to access).[/yellow]")
+
+ raise typer.Exit(code=1)
+
except Exception as e:
+ # 5. Handle unexpected exceptions
console.print(f"[bold red]An unexpected error occurred:[/bold red] {str(e)}")
raise typer.Exit(code=1)
diff --git a/skillnet-ai/src/skillnet_ai/client.py b/skillnet-ai/src/skillnet_ai/client.py
index e55dbb5..ccc7651 100644
--- a/skillnet-ai/src/skillnet_ai/client.py
+++ b/skillnet-ai/src/skillnet_ai/client.py
@@ -3,7 +3,7 @@ from typing import List, Optional, Dict, Any, Union
from pathlib import Path
from skillnet_ai.creator import SkillCreator
-from skillnet_ai.downloader import SkillDownloader
+from skillnet_ai.downloader import SkillDownloader, GitHubAPIError
from skillnet_ai.evaluator import SkillEvaluator, EvaluatorConfig
from skillnet_ai.searcher import SkillNetSearcher
from skillnet_ai.analyzer import SkillRelationshipAnalyzer
@@ -109,9 +109,25 @@ class SkillNetClient:
try:
installed_path = downloader.download(folder_url=url, target_dir=target_dir)
if not installed_path:
- raise SkillNetError("Download returned None. Check URL validity or permissions.")
+ # Raised only when download returns None (e.g., URL parsing failed, no files)
+ raise SkillNetError("Download failed: No files were found or downloaded.")
return os.path.abspath(installed_path)
+
+ except GitHubAPIError as e:
+ # 1. Base error message from GitHub
+ error_detail = f"GitHub API Error [{e.status_code}]: {e.message}"
+
+ # 2. Append actionable hints based on status code
+ if e.status_code == 403:
+ error_detail += " \n\n💡 Tip: You may have hit the GitHub API rate limit. Please provide a GitHub token to increase limits."
+ elif e.status_code == 404:
+ error_detail += " \n\n💡 Tip: Resource not found. Ensure the URL is correct and the repository is public, or provide a GitHub token for private repository access."
+
+ # 3. Raise the final error with the hint attached
+ raise SkillNetError(error_detail) from e
+
except Exception as e:
+ # Fallback for other unexpected errors
raise SkillNetError(f"Download failed: {str(e)}") from e
def create(
diff --git a/skillnet-ai/src/skillnet_ai/downloader.py b/skillnet-ai/src/skillnet_ai/downloader.py
index b545109..46f61b2 100644
--- a/skillnet-ai/src/skillnet_ai/downloader.py
+++ b/skillnet-ai/src/skillnet_ai/downloader.py
@@ -5,6 +5,17 @@ from typing import Optional, List, Dict, Tuple
logger = logging.getLogger(__name__)
+class GitHubAPIError(Exception):
+ """
+ Custom exception for GitHub API errors, encapsulating the status code
+ and the specific error message returned by GitHub.
+ """
+ def __init__(self, status_code: int, message: str):
+ self.status_code = status_code
+ self.message = message
+ super().__init__(f"GitHub API Error [{status_code}]: {message}")
+
+
class SkillDownloader:
"""
A class to handle downloading specific subdirectories from GitHub repositories
@@ -51,6 +62,7 @@ class SkillDownloader:
logger.info(f"Parsing repository details: {owner}/{repo} @ {ref} -> {dir_path}")
# 2. Fetch the file tree for the specific directory
+ # This may now raise a GitHubAPIError if rate limited or not found
files_to_download = self._get_file_tree(owner, repo, ref, dir_path)
if not files_to_download:
logger.warning(f"No matching files found or API error for path: {dir_path}")
@@ -88,6 +100,9 @@ class SkillDownloader:
return final_path
+ except GitHubAPIError:
+ # Allow the GitHub API error to bubble up to the client/CLI
+ raise
except Exception as e:
logger.error(f"Critical error during skill installation: {e}")
return None
@@ -136,9 +151,16 @@ class SkillDownloader:
try:
response = self.session.get(api_url)
+
if response.status_code != 200:
- logger.error(f"GitHub API Error [{response.status_code}]: {response.text}")
- return []
+ error_msg = response.text
+ try:
+ # Attempt to parse the exact message from GitHub's JSON response
+ error_msg = response.json().get("message", error_msg)
+ except ValueError:
+ pass # Retain raw text if parsing fails
+
+ raise GitHubAPIError(response.status_code, error_msg)
contents = response.json()
@@ -165,6 +187,9 @@ class SkillDownloader:
return files_to_download
+ except GitHubAPIError:
+ # Allow the custom exception to bubble up through recursive calls
+ raise
except Exception as e:
logger.error(f"Failed to retrieve file tree for {dir_path}: {e}")
return []