1#include <userver/protobuf/json/exceptions.hpp>
9namespace protobuf::json {
13template <
typename TErrorCode>
14[[nodiscard]]
constexpr const char* GetConversionErrorCodeStr(
const TErrorCode code)
noexcept {
15 if constexpr (std::is_same_v<TErrorCode, ParseErrorCode>) {
17 case TErrorCode::kUnknownField:
18 return "unknown field";
19 case TErrorCode::kUnknownEnum:
20 return "unknown enum";
21 case TErrorCode::kMultipleOneofFields:
22 return "multiple oneof fields";
23 case TErrorCode::kInvalidType:
24 return "invalid type";
25 case TErrorCode::kInvalidValue:
26 return "invalid value";
31 if (code == TErrorCode::kInvalidValue) {
32 return "invalid value";
39template <
typename TErrorCode>
40[[nodiscard]]
constexpr const char* GetConversionErrorDescription()
noexcept {
41 if constexpr (std::is_same_v<TErrorCode, ParseErrorCode>) {
42 return "Failed to convert JSON field '{}' with error '{}'";
44 return "Failed to convert protobuf message field '{}' with error '{}'";
50template <
typename TErrorCode>
51ConversionError<TErrorCode>::ConversionError(
const ConversionError<TErrorCode>::ErrorCodeType code, std::string path)
52 : ConversionErrorBase(
53 fmt::format(GetConversionErrorDescription<TErrorCode>(), path, GetConversionErrorCodeStr(code))
55 error_info_(code, std::move(path))
58template class ConversionError<ParseErrorCode>;
59template class ConversionError<PrintErrorCode>;