Error.hh
Go to the documentation of this file.
1/*
2 * Copyright 2017 Open Source Robotics Foundation
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*/
17#ifndef SDF_ERROR_HH_
18#define SDF_ERROR_HH_
19
20#include <iostream>
21#include <string>
22#include <optional>
23#include <gz/utils/ImplPtr.hh>
24#include <sdf/sdf_config.h>
25#include "sdf/Console.hh"
26#include "sdf/system_util.hh"
27
28#ifdef _WIN32
29// Disable warning C4251 which is triggered by
30// std::string
31#pragma warning(push)
32#pragma warning(disable: 4251)
33#endif
34
35namespace sdf
36{
37 // Inline bracket to help doxygen filtering.
38 inline namespace SDF_VERSION_NAMESPACE {
39 //
40
47 enum class ErrorCode
48 {
49 // \brief No error
50 NONE = 0,
51
53 FILE_READ,
54
57 DUPLICATE_NAME,
58
60 RESERVED_NAME,
61
63 ATTRIBUTE_MISSING,
64
66 ATTRIBUTE_INVALID,
67
69 ATTRIBUTE_DEPRECATED,
70
73 ATTRIBUTE_INCORRECT_TYPE,
74
76 ELEMENT_MISSING,
77
79 ELEMENT_INVALID,
80
82 ELEMENT_DEPRECATED,
83
87 ELEMENT_INCORRECT_TYPE,
88
90 ELEMENT_ERROR,
91
93 URI_INVALID,
94
96 URI_LOOKUP,
97
99 DIRECTORY_NONEXISTANT,
100
102 MODEL_CANONICAL_LINK_INVALID,
103
105 MODEL_WITHOUT_LINK,
106
108 NESTED_MODELS_UNSUPPORTED,
109
111 LINK_INERTIA_INVALID,
112
114 JOINT_CHILD_LINK_INVALID,
115
117 JOINT_PARENT_LINK_INVALID,
118
120 JOINT_PARENT_SAME_AS_CHILD,
121
124 FRAME_ATTACHED_TO_INVALID,
125
127 FRAME_ATTACHED_TO_CYCLE,
128
130 FRAME_ATTACHED_TO_GRAPH_ERROR,
131
134 POSE_RELATIVE_TO_INVALID,
135
137 POSE_RELATIVE_TO_CYCLE,
138
140 POSE_RELATIVE_TO_GRAPH_ERROR,
141
143 ROTATION_SNAP_CONFIG_ERROR,
144
146 STRING_READ,
147
149 MODEL_PLACEMENT_FRAME_INVALID,
150
152 VERSION_DEPRECATED,
153
156 MERGE_INCLUDE_UNSUPPORTED,
157
160 PARAMETER_ERROR,
161
164 UNKNOWN_PARAMETER_TYPE,
165
168 FATAL_ERROR,
169
171 WARNING,
172
175 JOINT_AXIS_EXPRESSED_IN_INVALID,
176
178 CONVERSION_ERROR,
179
181 PARSING_ERROR,
182
185 JOINT_AXIS_MIMIC_INVALID,
186
188 XML_ERROR,
189 };
190
192 {
194 public: Error();
195
200 public: Error(const ErrorCode _code, const std::string &_message);
201
207 public: Error(const ErrorCode _code, const std::string &_message,
208 const std::string &_filePath);
209
217 public: Error(const ErrorCode _code, const std::string &_message,
218 const std::string &_filePath, int _lineNumber);
219
223 public: ErrorCode Code() const;
224
227 public: std::string Message() const;
228
231 public: void SetMessage(const std::string &_message);
232
236 public: std::optional<std::string> FilePath() const;
237
241 public: void SetFilePath(const std::string &_filePath);
242
245 public: std::optional<int> LineNumber() const;
246
249 public: void SetLineNumber(int _lineNumber);
250
254 public: std::optional<std::string> XmlPath() const;
255
260 public: void SetXmlPath(const std::string &_xmlPath);
261
265 public: explicit operator bool() const;
266
274 public: bool operator==(const bool _value) const;
275
280 public: friend SDFORMAT_VISIBLE std::ostream &operator<<(
281 std::ostream &_out, const sdf::Error &_err);
282
284 GZ_UTILS_IMPL_PTR(dataPtr)
285 };
286
289 namespace internal
290 {
295 void SDFORMAT_VISIBLE throwOrPrintError(sdf::Console::ConsoleStream &_out,
296 const sdf::Error &_error);
297 } // namespace internal
298 } // namespace SDF_VERSION_NAMESPACE
299} // namespace sdf
300#ifdef _WIN32
301#pragma warning(pop)
302#endif
303
304
305#endif
Definition: Error.hh:192
std::string Message() const
Get the error message, which is a description of the error.
friend GZ_SDFORMAT_VISIBLE std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
std::optional< std::string > FilePath() const
Get the file path associated with this error.
Error(const ErrorCode _code, const std::string &_message, const std::string &_filePath, int _lineNumber)
Constructor.
bool operator==(const bool _value) const
Compare this Error to a boolean value.
void SetLineNumber(int _lineNumber)
Sets the line number that is associated with this error.
ErrorCode Code() const
Get the error code.
void SetFilePath(const std::string &_filePath)
Sets the file path that is associated with this error.
void SetMessage(const std::string &_message)
Sets the message associated with this error.
Error()
Default constructor.
void SetXmlPath(const std::string &_xmlPath)
Safe bool conversion.
Error(const ErrorCode _code, const std::string &_message, const std::string &_filePath)
Constructor.
std::optional< int > LineNumber() const
Get the line number associated with this error.
std::optional< std::string > XmlPath() const
Get the XPath-like trace that is associated with this error.
Error(const ErrorCode _code, const std::string &_message)
Constructor.
void GZ_SDFORMAT_VISIBLE throwOrPrintError(sdf::Console::ConsoleStream &_out, const sdf::Error &_error)
Prints the error to _out or throw using SDF_ASSERT depending on the ErrorCode in _error.
ErrorCode
Set of error codes.
Definition: Error.hh:48
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25