subspace_client_github/issue_report/
error.rs1use std::fmt;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum ErrorKind {
7 DescriptionRequired,
8 InvalidTitle,
9 InvalidDiagnostics,
10 BodyTooLong,
11 Authentication,
12 AccessDenied,
13 RepositoryUnavailable,
14 RateLimited,
15 Rejected,
16 UncertainCreation,
17}
18
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct Error {
21 kind: ErrorKind,
22}
23
24impl Error {
25 pub fn kind(&self) -> ErrorKind {
26 self.kind
27 }
28}
29
30impl From<ErrorKind> for Error {
32 fn from(kind: ErrorKind) -> Self {
33 Self { kind }
34 }
35}
36
37impl fmt::Display for Error {
38 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
39 let message = match self.kind {
40 ErrorKind::DescriptionRequired => "Enter a description before reporting the issue.",
41 ErrorKind::InvalidTitle => "Use a single-line title of at most 256 characters.",
42 ErrorKind::InvalidDiagnostics => {
43 "Automatic diagnostics are invalid. Reopen the report form."
44 }
45 ErrorKind::BodyTooLong => {
46 "The report exceeds GitHub's 65,536-character limit. Shorten it before sending."
47 }
48 ErrorKind::Authentication => {
49 "GitHub rejected the credential. Sign in again, then review and retry."
50 }
51 ErrorKind::AccessDenied => {
52 "GitHub denied access. Check repository access or use the browser editor."
53 }
54 ErrorKind::RepositoryUnavailable => {
55 "The issue repository is unavailable. Check access or use the browser editor."
56 }
57 ErrorKind::RateLimited => {
58 "GitHub's request limit was reached. Wait before trying again."
59 }
60 ErrorKind::Rejected => {
61 "GitHub rejected the report. Review the title and description before retrying."
62 }
63 ErrorKind::UncertainCreation => {
64 "GitHub may have created the issue. Check the repository's issues before retrying to avoid a duplicate."
65 }
66 };
67 formatter.write_str(message)
68 }
69}
70
71impl std::error::Error for Error {}