diff --git a/atc/parse_graph.cc b/atc/parse_graph.cc index 30ae377..1905073 100644 --- a/atc/parse_graph.cc +++ b/atc/parse_graph.cc @@ -893,7 +893,7 @@ FMK_FUNC_HOST_VISIBILITY Status ConvertOm(const char *model_file, const char *js if (is_covert_to_json) { GetGroupName(model_def); - Pb2Json::ToJson(model_def, kOmBlackFields, json_file, true); + ret = Pb2Json::ToJson(model_def, kOmBlackFields, json_file, true); } else { PrintModelInfo(&model_def); } @@ -917,8 +917,8 @@ FMK_FUNC_HOST_VISIBILITY Status ConvertPbtxtToJson(const char *model_file, const } GetGroupName(model_def); - Pb2Json::ToJson(model_def, kOmBlackFields, json_file, true); - return SUCCESS; + ret = Pb2Json::ToJson(model_def, kOmBlackFields, json_file, true); + return ret; } catch (const std::exception &e) { ErrorManager::GetInstance().ATCReportErrMessage("E19021", {"reason"}, {"Convert pbtxt to json failed, exception message[" + std::string(e.what()) + "]"}); diff --git a/parser/common/convert/pb2json.cc b/parser/common/convert/pb2json.cc index c52c9a1..791b8b2 100644 --- a/parser/common/convert/pb2json.cc +++ b/parser/common/convert/pb2json.cc @@ -33,13 +33,14 @@ namespace { const int kSignificantDigits = 10; } -FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void Pb2Json::ToJson(const ProtobufMsg &message, - const set &black_fields, - const char *json_file, bool enum2str) { +FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status Pb2Json::ToJson(const ProtobufMsg &message, + const set &black_fields, + const char *json_file, bool enum2str) { Json j; Message2Json(message, black_fields, j, enum2str); - ge::parser::ModelSaver::SaveJsonToFile(json_file, j); + return ge::parser::ModelSaver::SaveJsonToFile(json_file, j); } + // JSON parses non utf8 character throwing exceptions, so some fields need to be shielded through black fields FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void Pb2Json::Message2Json(const ProtobufMsg &message, const set &black_fields, Json &json, diff --git a/parser/common/convert/pb2json.h b/parser/common/convert/pb2json.h index f7726f1..4a13fe8 100644 --- a/parser/common/convert/pb2json.h +++ b/parser/common/convert/pb2json.h @@ -23,6 +23,7 @@ #include #include #include +#include "ge/ge_api_error_codes.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" #include "nlohmann/json.hpp" @@ -51,8 +52,8 @@ class Pb2Json { const ProtobufReflection *reflection, const std::set &black_fields, Json &json, bool enum2str); - static void ToJson(const ProtobufMsg &message, const std::set &black_fields, const char *json_file, - bool enum2str = false); + static Status ToJson(const ProtobufMsg &message, const std::set &black_fields, const char *json_file, + bool enum2str = false); protected: static void Enum2Json(const ProtobufEnumValueDescriptor *enum_value_desc, const ProtobufFieldDescriptor *field,