1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright © 2022 The Radicle Link Contributors

use thiserror::Error;

use crate::git;

#[derive(Debug, Error)]
pub enum Create {
    #[error(transparent)]
    Evaluate(Box<dyn std::error::Error + Send + Sync + 'static>),
    #[error(transparent)]
    CreateChange(#[from] git::change::error::Create),
    #[error("failed to updated references for during object creation")]
    Refs {
        #[source]
        err: Box<dyn std::error::Error + Send + Sync + 'static>,
    },
    #[error(transparent)]
    Io(#[from] std::io::Error),
    #[error("signer must belong to the author")]
    SignerIsNotAuthor,
}

impl Create {
    pub(crate) fn evaluate(err: impl std::error::Error + Send + Sync + 'static) -> Self {
        Self::Evaluate(Box::new(err))
    }
}

#[derive(Debug, Error)]
#[error("failed to remove object: {err}")]
pub struct Remove {
    #[source]
    pub(crate) err: Box<dyn std::error::Error + Send + Sync + 'static>,
}

#[derive(Debug, Error)]
pub enum Retrieve {
    #[error(transparent)]
    Evaluate(Box<dyn std::error::Error + Send + Sync + 'static>),
    #[error(transparent)]
    Git(#[from] git2::Error),
    #[error("failed to get references during object retrieval")]
    Refs {
        #[source]
        err: Box<dyn std::error::Error + Send + Sync + 'static>,
    },
    #[error(transparent)]
    Io(#[from] std::io::Error),
}

impl Retrieve {
    pub(crate) fn evaluate(err: impl std::error::Error + Send + Sync + 'static) -> Self {
        Self::Evaluate(Box::new(err))
    }
}

#[derive(Debug, Error)]
pub enum Update {
    #[error(transparent)]
    Evaluate(Box<dyn std::error::Error + Send + Sync + 'static>),
    #[error("no object found")]
    NoSuchObject,
    #[error(transparent)]
    CreateChange(#[from] git::change::error::Create),
    #[error("failed to get references during object update")]
    Refs {
        #[source]
        err: Box<dyn std::error::Error + Send + Sync + 'static>,
    },
    #[error(transparent)]
    Git(#[from] git2::Error),
    #[error(transparent)]
    Io(#[from] std::io::Error),
    #[error("signer must belong to the author")]
    SignerIsNotAuthor,
}

impl Update {
    pub(crate) fn evaluate(err: impl std::error::Error + Send + Sync + 'static) -> Self {
        Self::Evaluate(Box::new(err))
    }
}