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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use thiserror::Error;

use crate::{commons::errors::SubjectError, governance::error::RequestError};

#[derive(Error, Debug)]
#[allow(dead_code)]
pub enum EvaluatorError {
    #[error("A database error has ocurred at main component {0}")]
    DatabaseError(String),
    #[error("Channel not available")]
    ChannelNotAvailable,
    #[error("Create Request not allowed")]
    CreateRequestNotAllowed,
    #[error("JSON Deserialization failed")]
    JSONDeserializationFailed,
    #[error("Signature generation failed")]
    SignatureGenerationFailed,
}

#[derive(Error, Debug, Clone)]
#[allow(dead_code)]
pub enum EvaluatorErrorResponses {
    #[error("Create Request not allowed")]
    CreateRequestNotAllowed,
    #[error("Contract execution error: \"{0}\"")]
    ContractExecutionError(ExecutorErrorResponses),
}

#[derive(Error, Debug, Clone)]
#[allow(dead_code)]
pub enum ExecutorErrorResponses {
    #[error("Subject Error")]
    SubjectError(#[from] SubjectError),
    #[error("A database error has ocurred at main component {0}")]
    DatabaseError(String),
    #[error("Contract for schema {0} of governance {1} not found")]
    ContractNotFound(String, String),
    #[error("The contract could not be instantiated")]
    ContractNotInstantiated,
    #[error("Contract entrypoint not found")]
    ContractEntryPointNotFound,
    #[error("Contract execution failed")]
    ContractExecutionFailed,
    #[error("Function \"{0}\" could not be linked")]
    FunctionLinkingFailed(String),
    #[error("Deserialization of state failed")]
    StateJSONDeserializationFailed,
    #[error("Deserialization of JSON PATCH failed")]
    JSONPATCHDeserializationFailed,
    #[error("State hash generation failed")]
    StateHashGenerationFailed,
    #[error("Context hash generation failed")]
    ContextHashGenerationFailed,
    #[error("Invalid pointer provided by contract")]
    InvalidPointerPovided,
    #[error("Can't get roles of invokator")]
    RolesObtentionFailed,
    #[error("Cant genererate Contract Result")]
    CantGenerateContractResult,
    #[error("Our Gov Version is Lower than sender")]
    OurGovIsLower,
    #[error("Our Gov Version is Higher than sender")]
    OurGovIsHigher,
    #[error("Create Request not allowed")]
    CreateRequestNotAllowed,
    #[error("Governance module error {0}")]
    GovernanceError(#[from] RequestError),
    #[error("Schema compilation failed")]
    SchemaCompilationFailed,
    #[error("Value to string conversion failed")]
    ValueToStringConversionFailed,
    #[error("Borsh serialization failed")]
    BorshSerializationError,
    #[error("Borsh deerialization failed")]
    BorshDeserializationError,
    #[error("Contract not updated")]
    ContractNotUpdated,
    #[error("GovernanceNotFound")]
    GovernanceNotFound,
}

#[derive(Error, Debug, Clone)]
#[allow(dead_code)]
pub enum CompilerError {
    #[error("A database error has ocurred at main component {0}")]
    DatabaseError(String),
    #[error("Channel not available")]
    ChannelNotAvailable,
    #[error("Initialization process error: {0}")]
    InitError(String),
    #[error("Internal Error")]
    InternalError(#[from] CompilerErrorResponses),
}

#[derive(Error, Debug, Clone)]
#[allow(dead_code)]
pub enum CompilerErrorResponses {
    #[error("A database error has ocurred at main component {0}")]
    DatabaseError(String),
    #[error("BorshSerialize Contract Error")]
    BorshSerializeContractError,
    #[error("Write File Error")]
    WriteFileError,
    #[error("Folder {0} could not be created: {1}")]
    FolderNotCreated(String, String),
    #[error("Cargo Exec Error")]
    CargoExecError,
    #[error("Contract Addition Error")]
    AddContractFail,
    #[error("Governance Error")]
    GovernanceError(#[from] RequestError),
    #[error("Can't create folder at /tmp")]
    TempFolderCreationFailed,
    #[error("Invalid function import found in WAS module")]
    InvalidImportFound,
    #[error("No SDK found")]
    NoSDKFound,
}

#[derive(Error, Debug)]
pub enum GovernanceStateError {
    #[error("A member's name is duplicated")]
    DuplicatedMemberName,
    #[error("A member's ID is duplicated")]
    DuplicatedMemberID,
    #[error("A policy identifier is duplicated")]
    DuplicatedPolicyID,
    #[error("No governace policy detected")]
    NoGvernancePolicy,
    #[error("It is not allowed to specify a different schema for the governnace")]
    GovernanceShchemaIDDetected,
    #[error("Schema ID is does not have a policy")]
    NoCorrelationSchemaPolicy,
    #[error("There are policies not correlated to any schema")]
    PoliciesWithoutSchema,
    #[error("Role assigned to not defined schema")]
    InvalidRoleSchema,
    #[error("ID specified for Role::Who does not exist")]
    IdWhoRoleNoExist,
    #[error("Name specified for Role::Who does not exist")]
    NameWhoRoleNoExist
}