PDI 1.2.2

Data exchange made easy

error.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2020 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 <string>
31 #include <sstream>
32 
33 #include <paraconf.h>
34 
35 #include <pdi/pdi_fwd.h>
36 
37 #include <spdlog/fmt/fmt.h>
38 
39 namespace PDI {
40 
41 class PDI_EXPORT Error:
42  public std::exception
43 {
44 protected:
47 
49  std::string m_what;
50 
51 public:
55  Error(PDI_status_t errcode);
56 
63  template<typename S, typename... Args>
64  Error(PDI_status_t errcode, const S& format_str, Args&& ... args):
65  m_status{errcode},
66  m_what{fmt::format(format_str, std::forward<Args>(args)...)}
67  {}
68 
73  Error(PDI_status_t errcode, const char* message);
74 
75  const char* what() const noexcept override;
76 
80  PDI_status_t status() const noexcept;
81 
82 };
83 
84 class PDI_EXPORT Unavailable_error:
85  public Error
86 {
87 public:
88  template<typename S, typename... Args>
89  Unavailable_error(const S& format_str, Args&& ... args):
90  Error(PDI_UNAVAILABLE, std::string("Unavailable_error: ") + format_str, std::forward<Args>(args)...)
91  {}
92 
94 
95  Unavailable_error(const Unavailable_error&) = default;
96 };
97 
98 class PDI_EXPORT Config_error:
99  public Error
100 {
101 public:
102  template<typename S, typename... Args>
103  Config_error(PC_tree_t tree, const S& format_str, Args&& ... args):
105  {
106  std::ostringstream err_msg;
107  if (!PC_status(tree) && tree.node) {
108  if (tree.node->start_mark.line == tree.node->end_mark.line) {
109  err_msg << "Config_error in line " << tree.node->start_mark.line + 1 << ": ";
110  } else {
111  err_msg << "Config_error in lines " << tree.node->start_mark.line + 1 << " - " << tree.node->end_mark.line << ": ";
112  }
113  } else {
114  err_msg << "Config_error: ";
115  }
116  err_msg << fmt::format(format_str, std::forward<Args>(args)...);
117  m_what = err_msg.str();
118  }
119 
120  Config_error(Config_error&&) = default;
121 
122  Config_error(const Config_error&) = default;
123 };
124 
125 class PDI_EXPORT Value_error:
126  public Error
127 {
128 public:
129  template<typename S, typename... Args>
130  Value_error(const S& format_str, Args&& ... args):
131  Error(PDI_ERR_VALUE, std::string("Value_error: ") + format_str, std::forward<Args>(args)...)
132  {}
133 
134  Value_error(Value_error&&) = default;
135 
136  Value_error(const Value_error&) = default;
137 };
138 
139 class PDI_EXPORT Plugin_error:
140  public Error
141 {
142 public:
143  template<typename S, typename... Args>
144  Plugin_error(const S& format_str, Args&& ... args):
145  Error(PDI_ERR_PLUGIN, std::string("Plugin_error: ") + format_str, std::forward<Args>(args)...)
146  {}
147 
148  Plugin_error(Plugin_error&&) = default;
149 
150  Plugin_error(const Plugin_error&) = default;
151 };
152 
153 class PDI_EXPORT Impl_error:
154  public Error
155 {
156 public:
157  template<typename S, typename... Args>
158  Impl_error(const S& format_str, Args&& ... args):
159  Error(PDI_ERR_IMPL, std::string("Impl_error: ") + format_str, std::forward<Args>(args)...)
160  {}
161 
162  Impl_error(Impl_error&&) = default;
163 
164  Impl_error(const Impl_error&) = default;
165 };
166 
167 class PDI_EXPORT System_error:
168  public Error
169 {
170 public:
171  template<typename S, typename... Args>
172  System_error(const S& format_str, Args&& ... args):
173  Error(PDI_ERR_SYSTEM, std::string("System_error: ") + format_str, std::forward<Args>(args)...)
174  {}
175 
176  System_error(System_error&&) = default;
177 
178  System_error(const System_error&) = default;
179 };
180 
181 class PDI_EXPORT State_error:
182  public Error
183 {
184 public:
185  template<typename S, typename... Args>
186  State_error(const S& format_str, Args&& ... args):
187  Error(PDI_ERR_STATE, std::string("State_error: ") + format_str, std::forward<Args>(args)...)
188  {}
189 
190  State_error(State_error&&) = default;
191 
192  State_error(const State_error&) = default;
193 };
194 
195 class PDI_EXPORT Right_error:
196  public Error
197 {
198 public:
199  template<typename S, typename... Args>
200  Right_error(const S& format_str, Args&& ... args):
201  Error(PDI_ERR_RIGHT, std::string("Right_error: ") + format_str, std::forward<Args>(args)...)
202  {}
203 
204  Right_error(Right_error&&) = default;
205 
206  Right_error(const Right_error&) = default;
207 };
208 
209 class PDI_EXPORT Type_error:
210  public Error
211 {
212 public:
213  template<typename S, typename... Args>
214  Type_error(const S& format_str, Args&& ... args):
215  Error(PDI_ERR_TYPE, std::string("Type_error: ") + format_str, std::forward<Args>(args)...)
216  {}
217 
218  Type_error(Type_error&&) = default;
219 
220  Type_error(const Type_error&) = default;
221 };
222 
223 } // namespace PDI
224 
225 #endif // PDI_ERROR_H_
Definition: error.h:209
Definition: error.h:139
Right_error(const S &format_str, Args &&... args)
Definition: error.h:200
Type_error(const S &format_str, Args &&... args)
Definition: error.h:214
System_error(const S &format_str, Args &&... args)
Definition: error.h:172
PDI_status_t m_status
status of the error
Definition: error.h:46
Value_error(const S &format_str, Args &&... args)
Definition: error.h:130
on an input call, no such data is available
Definition: pdi.h:77
Unavailable_error(const S &format_str, Args &&... args)
Definition: error.h:89
A system error occured (OS, etc.)
Definition: pdi.h:87
Impl_error(const S &format_str, Args &&... args)
Definition: error.h:158
STL namespace.
A value expression is invalid.
Definition: pdi.h:81
The configuration file is invalid.
Definition: pdi.h:79
State_error(const S &format_str, Args &&... args)
Definition: error.h:186
A call to a function has been made at a wrong time (e.g.
Definition: pdi.h:91
Invalid type error.
Definition: pdi.h:95
Definition: error.h:84
Tried to load a non-existing plugin.
Definition: pdi.h:83
Definition: error.h:181
Definition: error.h:153
Definition: error.h:125
Definition: error.h:98
PDI_status_t
Error codes of PDI.
Definition: pdi.h:73
Definition: error.h:195
A conflict of onwership over a content has been raised.
Definition: pdi.h:93
Plugin_error(const S &format_str, Args &&... args)
Definition: error.h:144
Error(PDI_status_t errcode, const S &format_str, Args &&... args)
Creates a PDI error.
Definition: error.h:64
std::string m_what
message of the error
Definition: error.h:49
Definition: array_datatype.h:37
Definition: error.h:167
Definition: error.h:41
Implementation limitation (typically an unimplemented feature)
Definition: pdi.h:85
Config_error(PC_tree_t tree, const S &format_str, Args &&... args)
Definition: error.h:103