PDI 1.11.0

the PDI data interface

error.h
1/*******************************************************************************
2 * Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3 * Copyright (C) 2021 Institute of Bioorganic Chemistry Polish Academy of Science (PSNC)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of CEA nor the names of its contributors may be used to
14 * endorse or promote products derived from this software without specific
15 * prior written permission.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 ******************************************************************************/
25
26#ifndef PDI_ERROR_H_
27#define PDI_ERROR_H_
28
29#include <exception>
30#include <sstream>
31#include <string>
32
33#include <paraconf.h>
34
35#include <spdlog/spdlog.h>
36
37#include <pdi/pdi_fwd.h>
38
39namespace PDI {
40
41class PDI_EXPORT Error: public std::exception
42{
43protected:
46
48 std::string m_what;
49
50public:
55
62 template <typename... Args>
63 inline constexpr Error(PDI_status_t errcode, fmt::format_string<Args...> format_str, Args&&... args)
64 : m_status{errcode}
65 , m_what{fmt::format(format_str, std::forward<Args>(args)...)}
66 {}
67
72 Error(PDI_status_t errcode, const char* message);
73
74 const char* what() const noexcept override;
75
79 PDI_status_t status() const noexcept;
80};
81
82class PDI_EXPORT Spectree_error: public Error
83{
84public:
85 template <typename... Args>
86 Spectree_error(PC_tree_t tree, fmt::format_string<Args...> format_str, Args&&... args)
88 {
89 std::ostringstream err_msg;
90 if (!PC_status(tree) && tree.node) {
91 if (tree.node->start_mark.line == tree.node->end_mark.line) {
92 err_msg << "Spectree_error in line " << tree.node->start_mark.line + 1 << ": ";
93 } else {
94 err_msg << "Spectree_error in lines " << tree.node->start_mark.line + 1 << " - " << tree.node->end_mark.line << ": ";
95 }
96 } else {
97 err_msg << "Spectree_error: ";
98 }
99 err_msg << fmt::format(format_str, std::forward<Args>(args)...);
100 m_what = err_msg.str();
101 }
102
104
106};
107
108class PDI_EXPORT Value_error: public Error
109{
110public:
111 template <typename... Args>
112 inline constexpr Value_error(fmt::format_string<Args...> format_str, Args&&... args)
113 : Error(PDI_ERR_VALUE, "Value_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
114 {}
115
117
118 Value_error(const Value_error&) = default;
119};
120
121class PDI_EXPORT Plugin_error: public Error
122{
123public:
124 template <typename... Args>
125 inline constexpr Plugin_error(fmt::format_string<Args...> format_str, Args&&... args)
126 : Error(PDI_ERR_PLUGIN, "Plugin_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
127 {}
128
130
131 Plugin_error(const Plugin_error&) = default;
132};
133
134class PDI_EXPORT Impl_error: public Error
135{
136public:
137 template <typename... Args>
138 inline constexpr Impl_error(fmt::format_string<Args...> format_str, Args&&... args)
139 : Error(PDI_ERR_IMPL, "Impl_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
140 {}
141
142 Impl_error(Impl_error&&) = default;
143
144 Impl_error(const Impl_error&) = default;
145};
146
147class PDI_EXPORT System_error: public Error
148{
149public:
150 template <typename... Args>
151 inline constexpr System_error(fmt::format_string<Args...> format_str, Args&&... args)
152 : Error(PDI_ERR_SYSTEM, "System_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
153 {}
154
156
157 System_error(const System_error&) = default;
158};
159
160class PDI_EXPORT State_error: public Error
161{
162public:
163 template <typename... Args>
164 inline constexpr State_error(fmt::format_string<Args...> format_str, Args&&... args)
165 : Error(PDI_ERR_STATE, "State_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
166 {}
167
169
170 State_error(const State_error&) = default;
171};
172
173class PDI_EXPORT Permission_error: public Error
174{
175public:
176 template <typename... Args>
177 inline constexpr Permission_error(fmt::format_string<Args...> format_str, Args&&... args)
178 : Error(PDI_ERR_PERMISSION, "Permission_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
179 {}
180
182
184};
185
186class PDI_EXPORT Type_error: public Error
187{
188public:
189 template <typename... Args>
190 inline constexpr Type_error(fmt::format_string<Args...> format_str, Args&&... args)
191 : Error(PDI_ERR_TYPE, "Type_error: {}", fmt::format(format_str, std::forward<Args>(args)...))
192 {}
193
194 Type_error(Type_error&&) = default;
195
196 Type_error(const Type_error&) = default;
197};
198
199} // namespace PDI
200
201#endif // PDI_ERROR_H_
Error(PDI_status_t errcode)
Creates a PDI error without a message.
constexpr Error(PDI_status_t errcode, fmt::format_string< Args... > format_str, Args &&... args)
Creates a PDI error.
Definition error.h:63
PDI_status_t m_status
status of the error
Definition error.h:45
Error(PDI_status_t errcode, const char *message)
Creates a PDI error.
PDI_status_t status() const noexcept
Returns status of the error.
const char * what() const noexcept override
std::string m_what
message of the error
Definition error.h:48
Impl_error(const Impl_error &)=default
Impl_error(Impl_error &&)=default
constexpr Impl_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:138
Permission_error(const Permission_error &)=default
constexpr Permission_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:177
Permission_error(Permission_error &&)=default
constexpr Plugin_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:125
Plugin_error(Plugin_error &&)=default
Plugin_error(const Plugin_error &)=default
Spectree_error(const Spectree_error &)=default
Spectree_error(Spectree_error &&)=default
Spectree_error(PC_tree_t tree, fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:86
State_error(State_error &&)=default
constexpr State_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:164
State_error(const State_error &)=default
constexpr System_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:151
System_error(const System_error &)=default
System_error(System_error &&)=default
Type_error(Type_error &&)=default
Type_error(const Type_error &)=default
constexpr Type_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:190
Value_error(Value_error &&)=default
Value_error(const Value_error &)=default
constexpr Value_error(fmt::format_string< Args... > format_str, Args &&... args)
Definition error.h:112
PDI_status_t
Error codes of PDI.
Definition pdi.h:80
@ PDI_ERR_VALUE
A value expression is invalid.
Definition pdi.h:90
@ PDI_ERR_SPECTREE
Invalid entry in the specification tree.
Definition pdi.h:87
@ PDI_ERR_STATE
A call to a function has been made at a wrong time (e.g.
Definition pdi.h:100
@ PDI_ERR_TYPE
Invalid type error.
Definition pdi.h:105
@ PDI_ERR_PERMISSION
A conflict of ownership over a content has been raised.
Definition pdi.h:102
@ PDI_ERR_SYSTEM
A system error occurred (OS, etc.).
Definition pdi.h:96
@ PDI_ERR_IMPL
Implementation limitation (typically an unimplemented feature).
Definition pdi.h:94
@ PDI_ERR_PLUGIN
Tried to load a non-existing plugin.
Definition pdi.h:92
Definition array_datatype.h:38
Definition ref_any.h:737