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
84
85
86
87
88
89
90
91
92
93
94
95
use crate::governance::error::RequestError;
// use crate::ledger::errors::LedgerManagerError;
use thiserror::Error;

#[derive(Error, Debug, Clone, PartialEq)]
pub enum ProtocolErrors {
    #[error("Secret Key not found")]
    SignatureError,
    #[error("Channel unavaible")]
    ChannelError {
        #[from]
        source: crate::commons::errors::ChannelErrors,
    },
    #[error("Oneshot channel not available")]
    OneshotUnavailable,
    #[error("Ledger response not expected")]
    UnexpectedLedgerResponse,
    #[error("Not validator")]
    NotValidator,
    #[error("Governance error")]
    GovernanceError {
        #[from]
        source: RequestError,
    },
}

#[derive(Error, Debug, Clone)]
pub enum EventCreationError {
    #[error("No owner of subject")]
    NoOwnerOfSubject,
    #[error("Event creation not possible")]
    EventCreationNotAvailable,
    #[error("Subject not available for new events")]
    SubjectNotAvailable,
}

#[derive(Error, Debug, Clone)]
pub enum ResponseError {
    #[error("Subject not found")]
    SubjectNotFound,
    #[error("Event not found")]
    EventNotFound,
    #[error("Governance Error: {}", source)]
    GovernanceError {
        #[from]
        source: RequestError,
    },
    #[error("EventCreationError")]
    EventCreationError {
        #[from]
        source: EventCreationError,
    },
    #[error("Comunnication with Leyer closed")]
    LedgerChannelClosed,
    #[error("Comunnication with manager closed")]
    ComunnicationClosed,
    #[error("Unexpect Command Response")]
    UnexpectedCommandResponse,
    #[error("Not valid set operation")]
    InvalidSetOperation,
    #[error("Simulation failed")]
    SimulationFailed,
    #[error("Approval is not needed")]
    ApprovalNotNeeded,
    #[error("The event to be voted on has already been included in the chain")]
    EventAlreadyOnChain,
    #[error("Subject not synchronized")]
    NoSynchronizedSubject,
    #[error("Invalid invokation caller of event request")]
    InvalidCaller,
    #[error("Subject already being approved")]
    SubjectNotAvailable,
    #[error("The subject is being validated")]
    SubjectBeingValidated,
    #[error("SN not expected")]
    UnexpectedSN,
    #[error("Invalid Hash in ApprovalResponse")]
    InvalidHash,
    #[error("Can't process approval. The subject is not controlled by current node")]
    NotOwnerOfSubject,
    #[error("Voting is not required for the specified request")]
    VoteNotNeeded,
    #[error("Request not found")]
    RequestNotFound,
    #[error("Request already known")]
    RequestAlreadyKnown,
    #[error("Request Type not supported")]
    RequestTypeError,
    #[error("Event request verification against schema failed")]
    EventRequestVerificationFailed,
    #[error("Schema {0} not found")]
    SchemaNotFound(String),
    #[error("Governance subjects cannot refer to other governance and their schema_id must be \"governance\".")]
    CantCreateGovernance,
}