1use crate::LeoMessageCode;
19
20mod ast;
22pub use self::ast::*;
23
24mod cli;
26pub use self::cli::*;
27
28mod compiler;
30pub use self::compiler::*;
31
32mod flattener;
34pub use self::flattener::*;
35
36mod loop_unroller;
38pub use self::loop_unroller::*;
39
40mod const_eval;
42pub use self::const_eval::*;
43
44mod package;
46pub use self::package::*;
47
48mod parser;
50pub use self::parser::*;
51
52mod static_analyzer;
54pub use self::static_analyzer::*;
55
56mod type_checker;
58pub use self::type_checker::*;
59
60mod name_validation;
62pub use self::name_validation::*;
63
64mod check_interfaces;
66pub use self::check_interfaces::*;
67
68mod utils;
70pub use self::utils::*;
71
72#[derive(Debug, Error)]
75pub enum LeoError {
76 #[error(transparent)]
78 AstError(#[from] AstError),
79 #[error(transparent)]
81 CliError(#[from] CliError),
82 #[error(transparent)]
84 CompilerError(#[from] CompilerError),
85 #[error(transparent)]
87 ConstEvalError(#[from] ConstEvalError),
88 #[error(transparent)]
90 PackageError(#[from] PackageError),
91 #[error(transparent)]
93 ParserError(#[from] ParserError),
94 #[error(transparent)]
96 StaticAnalyzerError(#[from] StaticAnalyzerError),
97 #[error(transparent)]
99 TypeCheckerError(#[from] TypeCheckerError),
100 #[error(transparent)]
102 NameValidationError(#[from] NameValidationError),
103 #[error(transparent)]
105 CheckInterfacesError(#[from] CheckInterfacesError),
106 #[error(transparent)]
108 LoopUnrollerError(#[from] LoopUnrollerError),
109 #[error(transparent)]
111 FlattenError(#[from] FlattenError),
112 #[error("")]
115 LastErrorCode(i32),
116 #[error(transparent)]
118 UtilError(#[from] UtilError),
119 #[error(transparent)]
121 Anyhow(#[from] anyhow::Error),
122}
123
124impl LeoError {
125 pub fn error_code(&self) -> String {
127 use LeoError::*;
128
129 match self {
130 AstError(error) => error.error_code(),
131 CompilerError(error) => error.error_code(),
132 ConstEvalError(_) => "Const Eval Error".to_string(),
133 CliError(error) => error.error_code(),
134 ParserError(error) => error.error_code(),
135 PackageError(error) => error.error_code(),
136 StaticAnalyzerError(error) => error.error_code(),
137 TypeCheckerError(error) => error.error_code(),
138 NameValidationError(error) => error.error_code(),
139 CheckInterfacesError(error) => error.error_code(),
140 LoopUnrollerError(error) => error.error_code(),
141 FlattenError(error) => error.error_code(),
142 UtilError(error) => error.error_code(),
143 LastErrorCode(_) => unreachable!(),
144 Anyhow(_) => "SnarkVM Error".to_string(), }
146 }
147
148 pub fn exit_code(&self) -> i32 {
150 use LeoError::*;
151
152 match self {
153 AstError(error) => error.exit_code(),
154 CompilerError(error) => error.exit_code(),
155 ConstEvalError(_) => 1,
156 CliError(error) => error.exit_code(),
157 ParserError(error) => error.exit_code(),
158 PackageError(error) => error.exit_code(),
159 StaticAnalyzerError(error) => error.exit_code(),
160 TypeCheckerError(error) => error.exit_code(),
161 NameValidationError(error) => error.exit_code(),
162 CheckInterfacesError(error) => error.exit_code(),
163 LoopUnrollerError(error) => error.exit_code(),
164 FlattenError(error) => error.exit_code(),
165 UtilError(error) => error.exit_code(),
166 LastErrorCode(code) => *code,
167 Anyhow(_) => 11000, }
169 }
170}
171
172#[derive(Debug, Error, Hash, PartialEq, Eq)]
175pub enum LeoWarning {
176 #[error(transparent)]
178 ParserWarning(#[from] ParserWarning),
179 #[error(transparent)]
181 StaticAnalyzerWarning(#[from] StaticAnalyzerWarning),
182 #[error(transparent)]
184 TypeCheckerWarning(#[from] TypeCheckerWarning),
185}
186
187impl LeoWarning {
188 pub fn error_code(&self) -> String {
190 use LeoWarning::*;
191
192 match self {
193 ParserWarning(warning) => warning.warning_code(),
194 TypeCheckerWarning(warning) => warning.warning_code(),
195 StaticAnalyzerWarning(warning) => warning.warning_code(),
196 }
197 }
198}
199
200pub type Result<T, E = LeoError> = core::result::Result<T, E>;