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 <ignition/utils/ImplPtr.hh>
24 #include <sdf/sdf_config.h>
25 #include "sdf/system_util.hh"
26 
27 #ifdef _WIN32
28 // Disable warning C4251 which is triggered by
29 // std::string
30 #pragma warning(push)
31 #pragma warning(disable: 4251)
32 #endif
33 
34 namespace sdf
35 {
36  // Inline bracket to help doxygen filtering.
37  inline namespace SDF_VERSION_NAMESPACE {
38  //
39 
46  enum class ErrorCode
47  {
48  // \brief No error
49  NONE = 0,
50 
52  FILE_READ,
53 
57 
60 
63 
66 
69 
73 
76 
79 
82 
87 
90 
92  URI_LOOKUP,
93 
96 
99 
102 
105 
108 
111 
114 
117 
121 
124 
127 
131 
134 
137 
139  STRING_READ,
140 
143 
146  };
147 
149  {
151  public: Error();
152 
157  public: Error(const ErrorCode _code, const std::string &_message);
158 
164  public: Error(const ErrorCode _code, const std::string &_message,
165  const std::string &_filePath);
166 
174  public: Error(const ErrorCode _code, const std::string &_message,
175  const std::string &_filePath, int _lineNumber);
176 
180  public: ErrorCode Code() const;
181 
184  public: std::string Message() const;
185 
189  public: std::optional<std::string> FilePath() const;
190 
193  public: std::optional<int> LineNumber() const;
194 
198  public: explicit operator bool() const;
199 
207  public: bool operator==(const bool _value) const;
208 
213  public: friend std::ostream &operator<<(std::ostream &_out,
214  const sdf::Error &_err)
215  {
216  if (!_err.FilePath().has_value())
217  {
218  _out << "Error Code "
219  << static_cast<std::underlying_type<sdf::ErrorCode>::type>(
220  _err.Code())
221  << " Msg: " << _err.Message();
222  }
223  else if (!_err.LineNumber().has_value())
224  {
225  _out << "Error Code "
226  << static_cast<std::underlying_type<sdf::ErrorCode>::type>(
227  _err.Code())
228  << ": [" << _err.FilePath().value() << "]: "
229  << " Msg: " << _err.Message();
230  }
231  else
232  {
233  _out << "Error Code "
234  << static_cast<std::underlying_type<sdf::ErrorCode>::type>(
235  _err.Code())
236  << ": [" << _err.FilePath().value() << ":L"
237  << std::to_string(_err.LineNumber().value()) << "]: "
238  << " Msg: " << _err.Message();
239  }
240  return _out;
241  }
242 
244  IGN_UTILS_IMPL_PTR(dataPtr)
245  };
246  }
247 }
248 #ifdef _WIN32
249 #pragma warning(pop)
250 #endif
251 
252 
253 #endif
sdf::v11::Error
Definition: Error.hh:148
sdf::v11::ErrorCode::JOINT_PARENT_LINK_INVALID
@ JOINT_PARENT_LINK_INVALID
A joint has an invalid parent link.
sdf::v11::ErrorCode::JOINT_CHILD_LINK_INVALID
@ JOINT_CHILD_LINK_INVALID
A joint has an invalid child link.
sdf::v11::ErrorCode::URI_LOOKUP
@ URI_LOOKUP
A error occured while trying to resolve a URI.
sdf::v11::ErrorCode::MODEL_WITHOUT_LINK
@ MODEL_WITHOUT_LINK
A model without a link.
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:33
sdf::v11::Error::Code
ErrorCode Code() const
Get the error code.
sdf::v11::Error::operator<<
friend std::ostream & operator<<(std::ostream &_out, const sdf::Error &_err)
Output operator for an error.
Definition: Error.hh:213
sdf::v11::ErrorCode::DUPLICATE_NAME
@ DUPLICATE_NAME
A duplicate name was found for an element where unique names are required.
sdf::v11::ErrorCode::ELEMENT_INVALID
@ ELEMENT_INVALID
This error indicates that an SDF element is invalid.
sdf::v11::Error::Message
std::string Message() const
Get the error message, which is a description of the error.
sdf::v11::ErrorCode::DIRECTORY_NONEXISTANT
@ DIRECTORY_NONEXISTANT
A filesystem directory does not exist.
sdf::v11::ErrorCode::POSE_RELATIVE_TO_CYCLE
@ POSE_RELATIVE_TO_CYCLE
The pose relative-to graph contains a cycle.
sdf::v11::ErrorCode::FRAME_ATTACHED_TO_CYCLE
@ FRAME_ATTACHED_TO_CYCLE
The frame attached-to graph contains a cycle.
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:41
sdf::v11::Error::LineNumber
std::optional< int > LineNumber() const
Get the line number associated with this error.
sdf::v11::ErrorCode::URI_INVALID
@ URI_INVALID
A URI is invalid.
sdf::v11::ErrorCode::ATTRIBUTE_INVALID
@ ATTRIBUTE_INVALID
This error indicates that an SDF attribute is invalid.
sdf::v11::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::v11::ErrorCode::MODEL_PLACEMENT_FRAME_INVALID
@ MODEL_PLACEMENT_FRAME_INVALID
The specified placement frame is invalid.
sdf::v11::ErrorCode::ATTRIBUTE_INCORRECT_TYPE
@ ATTRIBUTE_INCORRECT_TYPE
Indicates an attribute was included that is not part of the sdf spec.
sdf::v11::ErrorCode::NESTED_MODELS_UNSUPPORTED
@ NESTED_MODELS_UNSUPPORTED
Indicates that a DOM object tried to read a nested model.
sdf::v11::ErrorCode::STRING_READ
@ STRING_READ
Indicates that reading an SDF string failed.
sdf::v11::ErrorCode::POSE_RELATIVE_TO_GRAPH_ERROR
@ POSE_RELATIVE_TO_GRAPH_ERROR
The pose relative-to graph has an internal error.
sdf::v11::ErrorCode::VERSION_DEPRECATED
@ VERSION_DEPRECATED
The provided version has been deprecated or it is pre-versioning.
sdf::v11::ErrorCode::ELEMENT_INCORRECT_TYPE
@ ELEMENT_INCORRECT_TYPE
Indicates that an incorrect SDF element type was encountered.
sdf::v11::Error::FilePath
std::optional< std::string > FilePath() const
Get the file path associated with this error.
sdf::v11::ErrorCode::FILE_READ
@ FILE_READ
Indicates that reading an SDF file failed.
sdf::v11::ErrorCode
ErrorCode
Definition: Error.hh:46
sdf::v11::ErrorCode::JOINT_PARENT_SAME_AS_CHILD
@ JOINT_PARENT_SAME_AS_CHILD
A joint has the same link specified as parent and child.
sdf::v11::ErrorCode::FRAME_ATTACHED_TO_GRAPH_ERROR
@ FRAME_ATTACHED_TO_GRAPH_ERROR
The frame attached-to graph has an internal error.
sdf::v11::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::v11::ErrorCode::ELEMENT_MISSING
@ ELEMENT_MISSING
Indicates that a required SDF element is missing.
sdf::v11::ErrorCode::ATTRIBUTE_MISSING
@ ATTRIBUTE_MISSING
Indicates that a required SDF attribute is missing.
sdf::v11::ErrorCode::LINK_INERTIA_INVALID
@ LINK_INERTIA_INVALID
A link has invalid inertia.
sdf::v11::ErrorCode::NONE
@ NONE
system_util.hh
sdf::v11::ErrorCode::RESERVED_NAME
@ RESERVED_NAME
A reserved name was used in an entity name attribute.
sdf::v11::ErrorCode::MODEL_CANONICAL_LINK_INVALID
@ MODEL_CANONICAL_LINK_INVALID
A model with an invalid canonical link.
sdf::v11::ErrorCode::ELEMENT_DEPRECATED
@ ELEMENT_DEPRECATED
This error indicates that an SDF element is deprecated.
sdf::v11::ErrorCode::ATTRIBUTE_DEPRECATED
@ ATTRIBUTE_DEPRECATED
This error indicates that an SDF attribute is deprecated.