3
0

JsonReportingHelper.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <Atom/RPI.Edit/Common/JsonReportingHelper.h>
  9. namespace AZ
  10. {
  11. namespace RPI
  12. {
  13. void JsonReportingHelper::Attach(JsonSerializerSettings& settings)
  14. {
  15. settings.m_reporting = [this](AZStd::string_view message, AZ::JsonSerializationResult::ResultCode resultCode, AZStd::string_view path)
  16. {
  17. return Reporting(message, resultCode, path);
  18. };
  19. }
  20. void JsonReportingHelper::Attach(JsonDeserializerSettings& settings)
  21. {
  22. settings.m_reporting = [this](AZStd::string_view message, AZ::JsonSerializationResult::ResultCode resultCode, AZStd::string_view path)
  23. {
  24. return Reporting(message, resultCode, path);
  25. };
  26. }
  27. bool JsonReportingHelper::WarningsReported() const
  28. {
  29. return m_warningsReported;
  30. }
  31. bool JsonReportingHelper::ErrorsReported() const
  32. {
  33. return m_errorsReported;
  34. }
  35. AZStd::string JsonReportingHelper::GetErrorMessage() const
  36. {
  37. return m_firstErrorMessage;
  38. }
  39. AZ::JsonSerializationResult::ResultCode JsonReportingHelper::Reporting(AZStd::string_view message, AZ::JsonSerializationResult::ResultCode result, [[maybe_unused]] AZStd::string_view path)
  40. {
  41. if (result.GetOutcome() == JsonSerializationResult::Outcomes::Skipped)
  42. {
  43. m_warningsReported = true;
  44. AZ_Warning("JSON", false, "Skipped unrecognized field '%.*s'", AZ_STRING_ARG(path));
  45. }
  46. else if (result.GetProcessing() != JsonSerializationResult::Processing::Completed ||
  47. result.GetOutcome() >= JsonSerializationResult::Outcomes::Unavailable)
  48. {
  49. if (result.GetOutcome() >= JsonSerializationResult::Outcomes::Catastrophic)
  50. {
  51. m_errorsReported = true;
  52. AZ_Error("JSON", false, "'%.*s': %.*s - %s", AZ_STRING_ARG(path), AZ_STRING_ARG(message), result.ToString("").c_str());
  53. if (m_firstErrorMessage.empty())
  54. {
  55. m_firstErrorMessage = message;
  56. }
  57. }
  58. else
  59. {
  60. m_warningsReported = true;
  61. AZ_Warning("JSON", false, "'%.*s': %.*s - %s", AZ_STRING_ARG(path), AZ_STRING_ARG(message), result.ToString("").c_str());
  62. }
  63. }
  64. return result;
  65. }
  66. } // namespace RPI
  67. } // namespace AZ