ErrorUtils.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "ErrorUtils.h"
  9. #include <sdf/sdf.hh>
  10. namespace ROS2::Utils
  11. {
  12. AZStd::string JoinSdfErrorsToString(AZStd::span<const sdf::Error> sdfErrors)
  13. {
  14. AZStd::string aggregateErrorMessages;
  15. AppendSdfErrorsToString(aggregateErrorMessages, sdfErrors);
  16. return aggregateErrorMessages;
  17. }
  18. void AppendSdfErrorsToString(AZStd::string& outputResult, AZStd::span<const sdf::Error> sdfErrors)
  19. {
  20. for (const sdf::Error& sdfError : sdfErrors)
  21. {
  22. AZStd::string errorMessage = AZStd::string::format("ErrorCode=%d", static_cast<int32_t>(sdfError.Code()));
  23. errorMessage += AZStd::string::format(", Message=%s", sdfError.Message().c_str());
  24. if (sdfError.LineNumber().has_value())
  25. {
  26. errorMessage += AZStd::string::format(", Line=%d", sdfError.LineNumber().value());
  27. }
  28. outputResult += errorMessage;
  29. outputResult += '\n';
  30. }
  31. }
  32. } // namespace ROS2::Utils