gh_docs_download/
error.rs1use thiserror::Error;
7
8pub type Result<T> = std::result::Result<T, GitHubDocsError>;
10
11#[derive(Debug, Error)]
17pub enum GitHubDocsError {
18 #[error("Invalid repository format: {input}. Expected format: 'owner/repo' or 'https://github.com/owner/repo'")]
20 InvalidRepoFormat {
21 input: String,
23 },
24
25 #[error("Repository '{owner}/{repo}' not found or access denied")]
27 RepositoryNotFound {
28 owner: String,
30 repo: String,
32 },
33
34 #[error("No documentation directories found in repository '{owner}/{repo}'")]
36 NoDocumentationFound {
37 owner: String,
39 repo: String,
41 },
42
43 #[error("Failed to download file '{path}': {reason}")]
45 DownloadFailed {
46 path: String,
48 reason: String,
50 },
51
52 #[error("Git operation failed: {command} - {stderr}")]
54 GitOperationFailed {
55 command: String,
57 stderr: String,
59 },
60
61 #[error("Invalid URL: {url}")]
63 InvalidUrl {
64 url: String,
66 },
67
68 #[error("File system operation failed")]
70 FileSystemError(#[from] std::io::Error),
71
72 #[error("URL parsing failed")]
74 UrlParseError(#[from] url::ParseError),
75
76 #[error("Path manipulation failed")]
78 PathError(#[from] std::path::StripPrefixError),
79
80 #[error("Directory traversal failed")]
82 WalkDirError(#[from] walkdir::Error),
83
84 #[error("Repository owner validation failed")]
86 RepoOwnerValidationError(#[from] RepoOwnerError),
87
88 #[error("Repository name validation failed")]
90 RepoNameValidationError(#[from] RepoNameError),
91}
92
93impl GitHubDocsError {
94 pub fn repository_not_found(owner: impl Into<String>, repo: impl Into<String>) -> Self {
96 Self::RepositoryNotFound {
97 owner: owner.into(),
98 repo: repo.into(),
99 }
100 }
101
102 pub fn no_documentation_found(owner: impl Into<String>, repo: impl Into<String>) -> Self {
104 Self::NoDocumentationFound {
105 owner: owner.into(),
106 repo: repo.into(),
107 }
108 }
109
110 pub fn download_failed(path: impl Into<String>, reason: impl Into<String>) -> Self {
112 Self::DownloadFailed {
113 path: path.into(),
114 reason: reason.into(),
115 }
116 }
117
118 pub fn git_operation_failed(command: impl Into<String>, stderr: impl Into<String>) -> Self {
120 Self::GitOperationFailed {
121 command: command.into(),
122 stderr: stderr.into(),
123 }
124 }
125}
126
127#[derive(Debug, Error)]
129pub enum RepoOwnerError {
130 #[error("Repository owner cannot be empty")]
132 Empty,
133 #[error("Repository owner contains invalid characters: {owner}")]
135 InvalidCharacters {
136 owner: String,
138 },
139 #[error("Repository owner is too long: {len} characters (max 39)")]
141 TooLong {
142 len: usize,
144 },
145}
146
147#[derive(Debug, Error)]
149pub enum RepoNameError {
150 #[error("Repository name cannot be empty")]
152 Empty,
153 #[error("Repository name contains invalid characters: {name}")]
155 InvalidCharacters {
156 name: String,
158 },
159 #[error("Repository name is too long: {len} characters (max 100)")]
161 TooLong {
162 len: usize,
164 },
165}