LIEF: Library to Instrument Executable Formats Version 0.17.0
Loading...
Searching...
No Matches
errors.hpp
Go to the documentation of this file.
1/* Copyright 2021 - 2025 R. Thomas
2 * Copyright 2021 - 2025 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 <cstdint>
19#include <LIEF/third-party/expected.hpp>
20#include <cstdint>
21
23enum class lief_errors : uint32_t {
28
31
35
39
42 /*
43 * When adding a new error, do not forget
44 * to update the Python bindings as well (pyErr.cpp) and Rust bindings:
45 * lief/src/error.rs
46 */
47};
48
49const char* to_string(lief_errors err);
50
52inline tl::unexpected<lief_errors> make_error_code(lief_errors e) {
53 return tl::make_unexpected(e);
54}
55
56
57namespace LIEF {
74template<typename T>
75using result = tl::expected<T, lief_errors>;
76
78template<class T>
80 return err.error();
81}
82
84template<class T>
86 return err.error();
87}
88
90struct ok_t {};
91
93inline ok_t ok() {
94 return ok_t{};
95}
96
110
111inline bool is_ok(const ok_error_t& val) {
112 return val.has_value();
113}
114
115inline bool is_err(const ok_error_t& val) {
116 return !is_ok(val);
117}
118
119}
120
121
122
123
124
125#endif
lief_errors
LIEF error codes definition.
Definition errors.hpp:23
@ require_extended_version
Definition errors.hpp:41
@ file_format_error
Definition errors.hpp:36
@ data_too_large
Definition errors.hpp:40
@ read_out_of_bound
Definition errors.hpp:32
@ conversion_error
Definition errors.hpp:30
@ build_error
Definition errors.hpp:38
@ not_implemented
Definition errors.hpp:26
@ not_found
Definition errors.hpp:25
@ corrupted
Definition errors.hpp:29
@ asn1_bad_tag
Definition errors.hpp:33
@ not_supported
Definition errors.hpp:27
@ read_error
Definition errors.hpp:24
@ parsing_error
Definition errors.hpp:37
@ file_error
Definition errors.hpp:34
tl::unexpected< lief_errors > make_error_code(lief_errors e)
Create an standard error code from lief_errors.
Definition errors.hpp:52
const char * to_string(lief_errors err)
LIEF namespace.
Definition Abstract/Binary.hpp:40
result< ok_t > ok_error_t
Opaque structure that is used by LIEF to avoid writing result<void> f(...). Instead,...
Definition errors.hpp:109
bool is_ok(const ok_error_t &val)
Definition errors.hpp:111
lief_errors get_error(result< T > &err)
Get the error code associated with the result.
Definition errors.hpp:79
ok_t ok()
Return success for function with return type ok_error_t.
Definition errors.hpp:93
bool is_err(const ok_error_t &val)
Definition errors.hpp:115
lief_errors as_lief_err(result< T > &err)
Return the lief_errors when the provided result<T> is an error.
Definition errors.hpp:85
tl::expected< T, lief_errors > result
Wrapper that contains an Object (T) or an error.
Definition errors.hpp:75
Opaque structure used by ok_error_t.
Definition errors.hpp:90