LIEF: Library to Instrument Executable Formats Version 0.15.0
Loading...
Searching...
No Matches
errors.hpp
1/* Copyright 2021 - 2024 R. Thomas
2 * Copyright 2021 - 2024 Quarkslab
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef LIEF_ERROR_H
17#define LIEF_ERROR_H
18#include <LIEF/third-party/expected.hpp>
19
21enum class lief_errors {
22 read_error = 1,
23 not_found,
24 not_implemented,
25 not_supported,
26
27 corrupted,
28 conversion_error,
29
30 read_out_of_bound,
31 asn1_bad_tag,
32 file_error,
33
34 file_format_error,
35 parsing_error,
36 build_error,
37
38 data_too_large,
39 /*
40 * When adding a new error, do not forget
41 * to update the Python bindings as well (pyErr.cpp)
42 *
43 */
44};
45
46const char* to_string(lief_errors err);
47
49inline tl::unexpected<lief_errors> make_error_code(lief_errors e) {
50 return tl::make_unexpected(e);
51}
52
53
54namespace LIEF {
71template<typename T>
72using result = tl::expected<T, lief_errors>;
73
75template<class T>
76lief_errors get_error(result<T>& err) {
77 return err.error();
78}
79
81template<class T>
82lief_errors as_lief_err(result<T>& err) {
83 return err.error();
84}
85
87struct ok_t {};
88
90inline ok_t ok() {
91 return ok_t{};
92}
93
107
108inline bool is_ok(const ok_error_t& val) {
109 return val.has_value();
110}
111
112inline bool is_err(const ok_error_t& val) {
113 return !is_ok(val);
114}
115
116}
117
118
119
120
121
122#endif
LIEF namespace.
Definition Abstract/Binary.hpp:32
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:106
lief_errors get_error(result< T > &err)
Get the error code associated with the result.
Definition errors.hpp:76
ok_t ok()
Return success for function with return type ok_error_t.
Definition errors.hpp:90
lief_errors as_lief_err(result< T > &err)
Return the lief_errors when the provided result<T> is an error.
Definition errors.hpp:82
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:72
Opaque structure used by ok_error_t.
Definition errors.hpp:87