@@ -103,29 +103,23 @@ static std::string GetFormattedStatusPropagationTrace(
103
103
auto status_propagation_trace = GetStatusPropagationTraceOrEmpty (status);
104
104
return status_propagation_trace.empty ()
105
105
? " "
106
- : absl::StrCat (" \n Status Propagation Trace:" ,
107
- status_propagation_trace.Flatten (), " \n " );
108
- }
109
-
110
- // Get the status message followed by a line break, if we are printing the
111
- // C++ stacktraces.
112
- //
113
- // This is needed so we have a blank line in between the status message and
114
- // the dumped C++ traces (either the status propagation one, or the C++
115
- // stacktrace).
116
- static std::string MaybeGetMessageWithLineBreak (const absl::Status& status) {
117
- return torch::get_cpp_stacktraces_enabled ()
118
- ? absl::StrCat (status.message (), " \n " )
119
- : std::string (status.message ());
106
+ : absl::StrCat (" \n\n Status Propagation Trace:" ,
107
+ status_propagation_trace.Flatten ());
120
108
}
121
109
122
110
std::string BuildStatusErrorMessage (const absl::Status& status) {
123
- return absl::StrCat (MaybeGetMessageWithLineBreak ( status),
111
+ return absl::StrCat (status. message ( ),
124
112
GetFormattedStatusPropagationTrace (status));
125
113
}
126
114
115
+ // Return a line break if torch::get_cpp_stacktraces_enabled() is true.
116
+ static std::string LineBreakIfCppStacktracesEnabled () {
117
+ return torch::get_cpp_stacktraces_enabled () ? " \n " : " " ;
118
+ }
119
+
127
120
void MaybeThrow (const absl::Status& status) {
128
- TORCH_CHECK (status.ok (), BuildStatusErrorMessage (status));
121
+ TORCH_CHECK (status.ok (), absl::StrCat (BuildStatusErrorMessage (status),
122
+ LineBreakIfCppStacktracesEnabled ()));
129
123
}
130
124
131
125
void GetValueOrThrow (const absl::Status& status) { MaybeThrow (status); }
0 commit comments