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