leo_errors/common/traits.rs
1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17/// MessageCode trait that all Errors should implement.
18pub trait LeoMessageCode: Sized {
19 /// Returns the error's exit code for the program.
20 fn exit_code(&self) -> i32;
21
22 /// Returns the prefixed error identifier.
23 fn error_code(&self) -> String;
24
25 /// Returns the prefixed warning identifier.
26 fn warning_code(&self) -> String;
27
28 /// Returns the messages's exit code mask, as to avoid conflicts.
29 fn code_mask() -> i32;
30
31 /// Returns the message's code type for the program.
32 fn message_type() -> String;
33
34 /// Returns if the message is an error or warning.
35 fn is_error() -> bool;
36
37 /// The LeoErrorCode which has a default code identifier of 037
38 /// (Leo upsidedown and backwards). This is to make the exit codes
39 /// unique to Leo itself.
40 #[inline(always)]
41 fn code_identifier() -> i8 {
42 37
43 }
44}