Skip to content

Commit

Permalink
Update error messages to be more descriptive (#3307)
Browse files Browse the repository at this point in the history
Summary:
Add the name of the network or model we are trying to load to the log
  messages we print at failures.

 Fixes #2647
Pull Request resolved: #3307

Test Plan:
Ran ninja test.
  Checked that the network name gets printed when an error happens at loading.

Differential Revision: D16513455

Pulled By: bertmaher

fbshipit-source-id: 87717508582de691150405063ead67d8239fe25b
  • Loading branch information
SameerAsal authored and facebook-github-bot committed Jul 26, 2019
1 parent 59f26ae commit 1c33634
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/Importer/Caffe2ModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ getSizeHW(ArgumentDictionaryTy &dict, const std::string &name,
llvm::Expected<caffe2::NetDef>
Caffe2ModelLoader::loadProtoFile(const std::string &filename) {
std::ifstream ff(filename, std::ios::in | std::ios::binary);
RETURN_ERR_IF_NOT(ff, "Can't find the model or network files.");

RETURN_ERR_IF_NOT(ff,
strFormat("Can't find the model or network files for %s",
filename.c_str()));
caffe2::NetDef net;

bool parseNet = false;
Expand Down
4 changes: 3 additions & 1 deletion lib/Importer/ONNXModelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ ONNXModelLoader::loadProto(const void *onnxModel, size_t onnxModelSize) {
llvm::Expected<ONNX_NAMESPACE::ModelProto>
ONNXModelLoader::loadProto(const std::string &filename) {
std::ifstream ff(filename, std::ios::in | std::ios::binary);
RETURN_ERR_IF_NOT(ff, "Can't find the model or network files.",
RETURN_ERR_IF_NOT(ff,
strFormat("Can't find the model or network files for %s.",
filename.c_str()),
GlowErr::ErrorCode::MODEL_LOADER_INVALID_PROTOBUF);

// TODO: intend to find a way to reuse the following function later
Expand Down
4 changes: 3 additions & 1 deletion tests/unittests/OnnxImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ using namespace std;
llvm::Expected<ONNX_NAMESPACE::ModelProto>
loadProto(const std::string &filename) {
std::ifstream ff(filename, std::ios::in | std::ios::binary);
RETURN_ERR_IF_NOT(ff, "Can't find the model or network files.",
RETURN_ERR_IF_NOT(ff,
strFormat("Can't find the model or network files for %s.",
filename.c_str()),
GlowErr::ErrorCode::MODEL_LOADER_INVALID_PROTOBUF);
if (filename.find(".onnxtxt") != std::string::npos) {
std::string str((std::istreambuf_iterator<char>(ff)),
Expand Down

0 comments on commit 1c33634

Please sign in to comment.