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
54
58
61
64
67
70
74
77
80
83
88
91
94
97
100
103
106
109
112
115
118
121
125
128
131
135
138
141
144
147
150
153
157
161
165
169
171 WARNING,
172
176
179
182
186 };
187
189 {
191 public: Error();
192
197 public: Error(const ErrorCode _code, const std::string &_message);
198
204 public: Error(const ErrorCode _code, const std::string &_message,
205 const std::string &_filePath);
206
214 public: Error(const ErrorCode _code, const std::string &_message,
215 const std::string &_filePath, int _lineNumber);
216
220 public: ErrorCode Code() const;
221
224 public: std::string Message() const;
225
228 public: void SetMessage(const std::string &_message);
229
233 public: std::optional<std::string> FilePath() const;
234
238 public: void SetFilePath(const std::string &_filePath);
239
242 public: std::optional<int> LineNumber() const;
243
246 public: void SetLineNumber(int _lineNumber);
247
251 public: std::optional<std::string> XmlPath() const;
252
257 public: void SetXmlPath(const std::string &_xmlPath);
258
262 public: explicit operator bool() const;
263
271 public: bool operator==(const bool _value) const;
272
277 public: friend SDFORMAT_VISIBLE std::ostream &operator<<(
278 std::ostream &_out, const sdf::Error &_err);
279
281 GZ_UTILS_IMPL_PTR(dataPtr)
282 };
283
286 namespace internal
287 {
292 void SDFORMAT_VISIBLE throwOrPrintError(sdf::Console::ConsoleStream &_out,
293 const sdf::Error &_error);
294 } // namespace internal
295 } // namespace SDF_VERSION_NAMESPACE
296} // namespace sdf
297#ifdef _WIN32
298#pragma warning(pop)
299#endif
300
301
302#endif
Definition: Error.hh:189
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
@ WARNING
Generic warning saved as error due to WarningsPolicy config.
@ VERSION_DEPRECATED
The provided version has been deprecated or it is pre-versioning.
@ FRAME_ATTACHED_TO_CYCLE
The frame attached-to graph contains a cycle.
@ LINK_INERTIA_INVALID
A link has invalid inertia.
@ FRAME_ATTACHED_TO_GRAPH_ERROR
The frame attached-to graph has an internal error.
@ POSE_RELATIVE_TO_GRAPH_ERROR
The pose relative-to graph has an internal error.
@ ELEMENT_DEPRECATED
This error indicates that an SDF element is deprecated.
@ DUPLICATE_NAME
A duplicate name was found for an element where unique names are required.
@ CONVERSION_ERROR
SDF conversion generic error.
@ JOINT_PARENT_LINK_INVALID
A joint has an invalid parent link.
@ ATTRIBUTE_INVALID
This error indicates that an SDF attribute is invalid.
@ URI_LOOKUP
A error occured while trying to resolve a URI.
@ ELEMENT_INVALID
This error indicates that an SDF element is invalid.
@ DIRECTORY_NONEXISTANT
A filesystem directory does not exist.
@ NESTED_MODELS_UNSUPPORTED
Indicates that a DOM object tried to read a nested model.
@ PARSING_ERROR
Generic error during parsing.
@ JOINT_AXIS_EXPRESSED_IN_INVALID
The joint axis expressed-in value does not match the name of an existing frame in the current scope.
@ PARAMETER_ERROR
Generic error type for parameters (values of SDFormat elements or attributes).
@ ELEMENT_MISSING
Indicates that a required SDF element is missing.
@ STRING_READ
Indicates that reading an SDF string failed.
@ FILE_READ
Indicates that reading an SDF file failed.
@ JOINT_CHILD_LINK_INVALID
A joint has an invalid child link.
@ JOINT_PARENT_SAME_AS_CHILD
A joint has the same link specified as parent and child.
@ ELEMENT_INCORRECT_TYPE
Indicates that an incorrect SDF element type was encountered.
@ MERGE_INCLUDE_UNSUPPORTED
Merge include is unspported for the type of entity being included, or the custom parser does not supp...
@ UNKNOWN_PARAMETER_TYPE
The specified parameter (values of SDFormat elements or attributes) type is unknown.
@ POSE_RELATIVE_TO_INVALID
The pose relative-to value does not match the name of an existing frame in the current scope.
@ MODEL_PLACEMENT_FRAME_INVALID
The specified placement frame is invalid.
@ ATTRIBUTE_DEPRECATED
This error indicates that an SDF attribute is deprecated.
@ FRAME_ATTACHED_TO_INVALID
The frame attached-to value does not match the name of an existing frame in the current scope.
@ FATAL_ERROR
Generic error to be thrown with SDF_ASSERT by the caller.
@ POSE_RELATIVE_TO_CYCLE
The pose relative-to graph contains a cycle.
@ ATTRIBUTE_MISSING
Indicates that a required SDF attribute is missing.
@ JOINT_AXIS_MIMIC_INVALID
The joint axis mimic does not refer to a valid joint in the current scope.
@ MODEL_WITHOUT_LINK
A model without a link.
@ MODEL_CANONICAL_LINK_INVALID
A model with an invalid canonical link.
@ ATTRIBUTE_INCORRECT_TYPE
Indicates an attribute was included that is not part of the sdf spec.
@ ROTATION_SNAP_CONFIG_ERROR
The rotation snap config provided is not valid.
@ ELEMENT_ERROR
Generic error type for Elements.
@ RESERVED_NAME
A reserved name was used in an entity name attribute.
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