diff --git a/mindspore/lite/include/errorcode.h b/mindspore/lite/include/errorcode.h index 72a51d71184..cf614708440 100644 --- a/mindspore/lite/include/errorcode.h +++ b/mindspore/lite/include/errorcode.h @@ -17,6 +17,8 @@ #ifndef MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ #define MINDSPORE_LITE_INCLUDE_ERRORCODE_H_ +#include + namespace mindspore { namespace lite { /// \brief STATUS defined for holding error code in MindSpore Lite. @@ -61,7 +63,9 @@ constexpr int RET_INPUT_PARAM_INVALID = -600; /**< Invalid input param by user. /// \brief Print description of errorcode. /// /// \param[in] error_code define return status of procedure. -void PrintErrorInfo(STATUS error_code); +/// +/// \return String of errorcode info. +std::string GetErrorInfo(STATUS error_code); } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/errorcode.cc b/mindspore/lite/src/errorcode.cc index e052af782d5..1c555fccb27 100644 --- a/mindspore/lite/src/errorcode.cc +++ b/mindspore/lite/src/errorcode.cc @@ -16,12 +16,11 @@ #include "include/errorcode.h" #include -#include #include namespace mindspore { namespace lite { -void PrintErrorInfo(STATUS status) { +std::string GetErrorInfo(STATUS status) { std::map info_map = {{RET_OK, "No error occurs."}, {RET_ERROR, "Common error code."}, {RET_NULL_PTR, "NULL pointer returned."}, @@ -42,7 +41,7 @@ void PrintErrorInfo(STATUS status) { {RET_INFER_ERR, "Failed to infer shape."}, {RET_INFER_INVALID, "Invalid infer shape before runtime."}, {RET_INPUT_PARAM_INVALID, "Invalid input param by user."}}; - std::cout << info_map[status] << std::endl; + return info_map.find(status) == info_map.end() ? "Unknown error" : info_map[status]; } } // namespace lite } // namespace mindspore diff --git a/mindspore/lite/src/lite_session.cc b/mindspore/lite/src/lite_session.cc index 75b0bf7d3a9..0a4b0923b46 100644 --- a/mindspore/lite/src/lite_session.cc +++ b/mindspore/lite/src/lite_session.cc @@ -269,6 +269,11 @@ int LiteSession::CompileGraph(Model *model) { is_running_.store(false); return RET_PARAM_INVALID; } + if (model->buf == nullptr) { + MS_LOG(ERROR) << "The input model buf is nullptr."; + is_running_.store(false); + return RET_PARAM_INVALID; + } auto ret = ConvertTensors(model); if (ret != RET_OK) { diff --git a/mindspore/lite/tools/converter/converter.cc b/mindspore/lite/tools/converter/converter.cc index e1e047b9355..a8ce4ebc132 100644 --- a/mindspore/lite/tools/converter/converter.cc +++ b/mindspore/lite/tools/converter/converter.cc @@ -106,18 +106,17 @@ MetaGraphT *Converter::Convert(const converter::Flags *flag) { int RunConverter(int argc, const char **argv) { std::unique_ptr flags(new (std::nothrow) converter::Flags); if (flags == nullptr) { - MS_LOG(ERROR) << "new flags error "; - std::cout << "NEW FLAGS ERROR:" << RET_MEMORY_FAILED << std::endl; - PrintErrorInfo(RET_MEMORY_FAILED); + MS_LOG(ERROR) << "NEW FLAGS ERROR:" << RET_MEMORY_FAILED << " " << GetErrorInfo(RET_MEMORY_FAILED); + std::cout << "NEW FLAGS ERROR:" << RET_MEMORY_FAILED << " " << GetErrorInfo(RET_MEMORY_FAILED) << std::endl; return RET_MEMORY_FAILED; } auto status = flags->Init(argc, argv); if (status != RET_OK) { if (status != RET_SUCCESS_EXIT) { - MS_LOG(ERROR) << "converter::Flags Init failed: " << status; - std::cout << "CONVERTER::FLAGS INIT FAILED:" << status << std::endl; + MS_LOG(ERROR) << "CONVERTER::FLAGS INIT FAILED:" << status << " " << GetErrorInfo(status) << std::endl; + std::cout << "CONVERTER::FLAGS INIT FAILED:" << status << " " << GetErrorInfo(status) << std::endl; } - PrintErrorInfo(status); + std::cout << GetErrorInfo(status) << std::endl; return status; } // Load graph @@ -147,18 +146,18 @@ int RunConverter(int argc, const char **argv) { fb_graph = onnxConverter.Convert(flags.get()); } break; default: { - MS_LOG(ERROR) << "Unsupported fmkType: " << flags->fmk; - std::cout << "UNSUPPORTED FMKTYPE " << flags->fmk << ":" << RET_INPUT_PARAM_INVALID << std::endl; - PrintErrorInfo(RET_INPUT_PARAM_INVALID); + MS_LOG(ERROR) << "UNSUPPORTED FMKTYPE " << flags->fmk << ":" << RET_INPUT_PARAM_INVALID << " " + << GetErrorInfo(RET_INPUT_PARAM_INVALID); + std::cout << "UNSUPPORTED FMKTYPE " << flags->fmk << ":" << RET_INPUT_PARAM_INVALID << " " + << GetErrorInfo(RET_INPUT_PARAM_INVALID) << std::endl; return RET_INPUT_PARAM_INVALID; } } NoSupportOp::GetInstance()->PrintOps(); status = ReturnCode::GetSingleReturnCode()->GetReturnCode(); if (fb_graph == nullptr) { - MS_LOG(ERROR) << "Convert model return nullptr"; - std::cout << "CONVERT RESULT FAILED:" << status << std::endl; - PrintErrorInfo(status); + MS_LOG(ERROR) << "CONVERT RESULT FAILED:" << status << " " << GetErrorInfo(status); + std::cout << "CONVERT RESULT FAILED:" << status << " " << GetErrorInfo(status) << std::endl; return status; } @@ -167,16 +166,14 @@ int RunConverter(int argc, const char **argv) { fb_graph->version = Version(); status = storage.Save(*fb_graph, flags->outputFile); if (status != RET_OK) { - MS_LOG(ERROR) << "Save graph to file failed"; - std::cout << "SAVE GRAPH FAILED:" << status << std::endl; - PrintErrorInfo(status); + MS_LOG(ERROR) << "SAVE GRAPH FAILED:" << status << " " << GetErrorInfo(status); + std::cout << "SAVE GRAPH FAILED:" << status << " " << GetErrorInfo(status) << std::endl; return status; } delete fb_graph; - MS_LOG(INFO) << "CONVERT RESULT: SUCCESS!"; + MS_LOG(INFO) << "CONVERT RESULT SUCCESS:" << status; std::cout << "CONVERT RESULT SUCCESS:" << status << std::endl; - PrintErrorInfo(status); return status; } } // namespace lite