diff --git a/mindspore/core/utils/status.cc b/mindspore/core/utils/status.cc index ba348dd2e98..eed10288b31 100644 --- a/mindspore/core/utils/status.cc +++ b/mindspore/core/utils/status.cc @@ -32,6 +32,59 @@ struct Status::Data { std::string err_description; }; +static std::map status_info_map = { + {kSuccess, "No error occurs."}, + // Core + {kCoreFailed, "Common error code."}, + // MD + {kMDOutOfMemory, "Out of memory"}, + {kMDShapeMisMatch, "Shape is incorrect"}, + {kMDInterrupted, "Interrupted system call"}, + {kMDNoSpace, "No space left on device"}, + {kMDPyFuncException, "Exception thrown from PyFunc"}, + {kMDDuplicateKey, "Duplicate key"}, + {kMDPythonInterpreterFailure, ""}, + {kMDTDTPushFailure, "Unexpected error"}, + {kMDFileNotExist, "Unexpected error"}, + {kMDProfilingError, "Error encountered while profiling"}, + {kMDBoundingBoxOutOfBounds, "Unexpected error"}, + {kMDBoundingBoxInvalidShape, "Unexpected error"}, + {kMDSyntaxError, "Syntax error"}, + {kMDTimeOut, "Unexpected error"}, + {kMDBuddySpaceFull, "BuddySpace full"}, + {kMDNetWorkError, "Network error"}, + {kMDNotImplementedYet, "Unexpected error"}, + {kMDUnexpectedError, "Unexpected error"}, + // ME + {kMEFailed, "Common error code."}, + {kMEInvalidInput, "Invalid input."}, + // MC + {kMCFailed, "Common error code."}, + {kMCDeviceError, "Device error."}, + {kMCInvalidInput, "Invalid input."}, + {kMCInvalidArgs, "Invalid arguments."}, + // Lite + {kLiteError, "Common error code."}, + {kLiteNullptr, "NULL pointer returned."}, + {kLiteParamInvalid, "Invalid parameter."}, + {kLiteNoChange, "No change."}, + {kLiteSuccessExit, "No error but exit."}, + {kLiteMemoryFailed, "Fail to create memory."}, + {kLiteNotSupport, "Fail to support."}, + {kLiteThreadPoolError, "Thread pool error."}, + {kLiteOutOfTensorRange, "Failed to check range."}, + {kLiteInputTensorError, "Failed to check input tensor."}, + {kLiteReentrantError, "Exist executor running."}, + {kLiteGraphFileError, "Failed to verify graph file."}, + {kLiteNotFindOp, "Failed to find operator."}, + {kLiteInvalidOpName, "Invalid operator name."}, + {kLiteInvalidOpAttr, "Invalid operator attr."}, + {kLiteOpExecuteFailure, "Failed to execution operator."}, + {kLiteFormatError, "Failed to checking tensor format."}, + {kLiteInferError, "Failed to infer shape."}, + {kLiteInferInvalid, "Invalid infer shape before runtime."}, + {kLiteInputParamInvalid, "Invalid input param by user."}}; + Status::Status() : data_(std::make_shared()) {} Status::Status(enum StatusCode status_code, const std::vector &status_msg) : data_(std::make_shared()) { @@ -40,7 +93,11 @@ Status::Status(enum StatusCode status_code, const std::vector &status_msg) } data_->err_description = CharToString(status_msg); - data_->status_msg = CharToString(status_msg); + if (!status_msg.empty()) { + data_->status_msg = CharToString(status_msg); + } else { + data_->status_msg = CodeAsString(status_code); + } data_->status_code = status_code; } @@ -105,59 +162,8 @@ std::vector Status::GetErrDescriptionChar() const { } std::vector Status::CodeAsCString(enum StatusCode c) { - static std::map info_map = {{kSuccess, "No error occurs."}, - // Core - {kCoreFailed, "Common error code."}, - // MD - {kMDOutOfMemory, "Out of memory"}, - {kMDShapeMisMatch, "Shape is incorrect"}, - {kMDInterrupted, "Interrupted system call"}, - {kMDNoSpace, "No space left on device"}, - {kMDPyFuncException, "Exception thrown from PyFunc"}, - {kMDDuplicateKey, "Duplicate key"}, - {kMDPythonInterpreterFailure, ""}, - {kMDTDTPushFailure, "Unexpected error"}, - {kMDFileNotExist, "Unexpected error"}, - {kMDProfilingError, "Error encountered while profiling"}, - {kMDBoundingBoxOutOfBounds, "Unexpected error"}, - {kMDBoundingBoxInvalidShape, "Unexpected error"}, - {kMDSyntaxError, "Syntax error"}, - {kMDTimeOut, "Unexpected error"}, - {kMDBuddySpaceFull, "BuddySpace full"}, - {kMDNetWorkError, "Network error"}, - {kMDNotImplementedYet, "Unexpected error"}, - {kMDUnexpectedError, "Unexpected error"}, - // ME - {kMEFailed, "Common error code."}, - {kMEInvalidInput, "Invalid input."}, - // MC - {kMCFailed, "Common error code."}, - {kMCDeviceError, "Device error."}, - {kMCInvalidInput, "Invalid input."}, - {kMCInvalidArgs, "Invalid arguments."}, - // Lite - {kLiteError, "Common error code."}, - {kLiteNullptr, "NULL pointer returned."}, - {kLiteParamInvalid, "Invalid parameter."}, - {kLiteNoChange, "No change."}, - {kLiteSuccessExit, "No error but exit."}, - {kLiteMemoryFailed, "Fail to create memory."}, - {kLiteNotSupport, "Fail to support."}, - {kLiteThreadPoolError, "Thread pool error."}, - {kLiteOutOfTensorRange, "Failed to check range."}, - {kLiteInputTensorError, "Failed to check input tensor."}, - {kLiteReentrantError, "Exist executor running."}, - {kLiteGraphFileError, "Failed to verify graph file."}, - {kLiteNotFindOp, "Failed to find operator."}, - {kLiteInvalidOpName, "Invalid operator name."}, - {kLiteInvalidOpAttr, "Invalid operator attr."}, - {kLiteOpExecuteFailure, "Failed to execution operator."}, - {kLiteFormatError, "Failed to checking tensor format."}, - {kLiteInferError, "Failed to infer shape."}, - {kLiteInferInvalid, "Invalid infer shape before runtime."}, - {kLiteInputParamInvalid, "Invalid input param by user."}}; - auto iter = info_map.find(c); - return StringToChar(iter == info_map.end() ? "Unknown error" : iter->second); + auto iter = status_info_map.find(c); + return StringToChar(iter == status_info_map.end() ? "Unknown error" : iter->second); } std::ostream &operator<<(std::ostream &os, const Status &s) { diff --git a/mindspore/lite/examples/quick_start_cpp/main.cc b/mindspore/lite/examples/quick_start_cpp/main.cc index 8b399507b77..555eb3f0e4a 100644 --- a/mindspore/lite/examples/quick_start_cpp/main.cc +++ b/mindspore/lite/examples/quick_start_cpp/main.cc @@ -154,7 +154,7 @@ int QuickStart(int argc, const char **argv) { delete[](model_buf); if (build_ret != mindspore::kSuccess) { delete model; - std::cerr << "Build model error " << build_ret.StatusCode() << std::endl; + std::cerr << "Build model error " << build_ret << std::endl; return -1; } @@ -174,7 +174,7 @@ int QuickStart(int argc, const char **argv) { auto predict_ret = model->Predict(inputs, &outputs); if (predict_ret != mindspore::kSuccess) { delete model; - std::cerr << "Predict error " << predict_ret.StatusCode() << std::endl; + std::cerr << "Predict error " << predict_ret << std::endl; return -1; }