Skip to content

Commit efd8f70

Browse files
ezyangfacebook-github-bot
authored andcommitted
Make msg() and msg_with_backtrace() private (pytorch#37094)
Summary: Pull Request resolved: pytorch#37094 Signed-off-by: Edward Z. Yang <[email protected]> Test Plan: Imported from OSS Differential Revision: D21202892 Pulled By: ezyang fbshipit-source-id: d59e6bffabd90cc734056bdce2cd1fe63262fab8
1 parent 6dd1bea commit efd8f70

File tree

8 files changed

+11
-19
lines changed

8 files changed

+11
-19
lines changed

c10/test/util/logging_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ TEST(LoggingTest, TestEnforceEquals) {
3434
// This should never be triggered.
3535
ADD_FAILURE();
3636
} catch (const ::c10::Error& err) {
37-
EXPECT_NE(err.msg().find("5 vs 6"), string::npos);
37+
EXPECT_NE(std::string(err.what()).find("5 vs 6"), string::npos);
3838
}
3939

4040
// arguments are expanded only once

c10/util/Exception.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ class C10_API Error : public std::exception {
5858

5959
void AppendMessage(const std::string& msg);
6060

61-
// Compute the full message from msg_ and msg_without_backtrace_
62-
// TODO: Maybe this should be private
63-
std::string msg() const;
64-
std::string msg_without_backtrace() const;
65-
6661
const std::vector<std::string>& msg_stack() const {
6762
return msg_stack_;
6863
}
@@ -80,6 +75,11 @@ class C10_API Error : public std::exception {
8075
const char* what_without_backtrace() const noexcept {
8176
return msg_without_backtrace_.c_str();
8277
}
78+
79+
private:
80+
// Compute the full message from msg_ and msg_without_backtrace_
81+
std::string msg() const;
82+
std::string msg_without_backtrace() const;
8383
};
8484

8585
class C10_API WarningHandler {

caffe2/core/operator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ TensorShapes InferBlobShapesAndTypes(
580580
}
581581

582582
} catch (::caffe2::EnforceNotMet& enf) {
583-
LOG(ERROR) << "Shape inference error: " << enf.msg();
583+
LOG(ERROR) << "Shape inference error: " << enf.what();
584584
LOG(ERROR) << "Operator: " << ProtoDebugString(op) << std::endl;
585585
LOG(ERROR) << "Returning empty results.";
586586

caffe2/core/operator_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ TEST(OperatorTest, ExceptionWorks) {
114114
// This should not happen - exception should throw above.
115115
LOG(FATAL) << "This should not happen.";
116116
} catch (const EnforceNotMet& err) {
117-
LOG(INFO) << err.msg();
117+
LOG(INFO) << err.what();
118118
}
119119
try {
120120
op->RunAsync();
121121
// This should not happen - exception should throw above.
122122
LOG(FATAL) << "This should not happen.";
123123
} catch (const EnforceNotMet& err) {
124-
LOG(INFO) << err.msg();
124+
LOG(INFO) << err.what();
125125
}
126126
}
127127

caffe2/mobile/contrib/ios/ios_caffe.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ Caffe2IOSPredictor* MakeCaffe2Predictor(const std::string& init_net_str,
1717
try {
1818
predictor = Caffe2IOSPredictor::NewCaffe2IOSPredictor(
1919
init_net, predict_net, disableMultithreadProcessing, allowMetalOperators);
20-
} catch (const caffe2::EnforceNotMet& e) {
21-
std::string error = e.msg();
22-
errorMessage.swap(error);
23-
return NULL;
2420
} catch (const std::exception& e) {
2521
std::string error = e.what();
2622
errorMessage.swap(error);

caffe2/mobile/contrib/ios/ios_caffe_predictor.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ void Caffe2IOSPredictor::run(const Tensor& inData, Tensor& outData, std::string&
5757
caffe2::Predictor::TensorList output_vec;
5858
try {
5959
predictor_(input_vec, &output_vec);
60-
} catch (const caffe2::EnforceNotMet& e) {
61-
std::string error = e.msg();
62-
errorMessage.swap(error);
63-
return;
6460
} catch (const std::exception& e) {
6561
std::string error = e.what();
6662
errorMessage.swap(error);

caffe2/opt/bound_shape_inferencer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void BoundShapeInferencer::InferCommonOp(const OperatorDef& op) {
820820
}
821821
} catch (const caffe2::EnforceNotMet& e) {
822822
LOG(ERROR) << "Enforce not met while inferring shapes for " << op.type()
823-
<< ": " << e.msg() << " first output: " << op.output(0);
823+
<< ": " << e.what() << " first output: " << op.output(0);
824824
} catch (const std::exception& e) {
825825
LOG(WARNING) << "Caught exception while inferring shapes for " << op.type()
826826
<< ": " << e.what() << " first output: " << op.output(0);

torch/csrc/jit/runtime/exception_message.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ inline std::ostream& operator<<(
2020
const ExceptionMessage& msg) {
2121
auto c10_error = dynamic_cast<const c10::Error*>(&msg.e_);
2222
if (c10_error) {
23-
out << c10_error->msg_without_backtrace();
23+
out << c10_error->what_without_backtrace();
2424
} else {
2525
out << msg.e_.what();
2626
}

0 commit comments

Comments
 (0)