@@ -139,9 +139,10 @@ constexpr char kStatusPropagationTraceKey[] =
139
139
// If `FnThatReturnStatus()` returns a non-ok status, this macro will
140
140
// call `ABSL_CHECK()`, which will crash.
141
141
//
142
- #define XLA_CHECK_OK (status, ...) \
143
- ::torch_xla::OkOrDie (::torch_xla::status_internal::GetStatus(status), \
144
- __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
142
+ #define XLA_CHECK_OK (status, ...) \
143
+ ::torch_xla::status_internal::OkOrDie ( \
144
+ ::torch_xla::status_internal::GetStatus (status), __FILE__, __LINE__, \
145
+ __FUNCTION__, ##__VA_ARGS__)
145
146
146
147
namespace status_internal {
147
148
@@ -190,6 +191,14 @@ absl::Status MaybeWithNewMessage(const absl::Status& status, const char* file,
190
191
int32_t line, const char * function,
191
192
std::string_view new_message = " " );
192
193
194
+ // Checks that `status` is an ok status.
195
+ //
196
+ // Otherwise, it will create a new status instance with the given source
197
+ // location information, and incorporate its message (alongside the
198
+ // status propagation trace) to the crash report.
199
+ void OkOrDie (const absl::Status& status, const char * file, const int32_t line,
200
+ const char * function, std::string_view message = " " );
201
+
193
202
} // namespace status_internal
194
203
195
204
// Builds the complete error message for the given `status`.
@@ -200,43 +209,35 @@ absl::Status MaybeWithNewMessage(const absl::Status& status, const char* file,
200
209
// It doesn't add a trailing line break.
201
210
std::string BuildStatusErrorMessage (const absl::Status& status);
202
211
203
- // Maybe throws an exception if `status` has a non-ok code.
212
+ // Throws an exception if `status` has a non-ok code.
204
213
//
205
214
// Ideally, this function should be used only used in the project's
206
215
// boundary, e.g. when we need to throw an exception for the user to see.
207
- void MaybeThrow (const absl::Status& status);
216
+ void OkOrThrow (const absl::Status& status);
208
217
209
218
// Either returns the value `status` holds, if it's an ok-status, or throw an
210
219
// exception from its error status.
211
220
template <class T >
212
221
T& GetValueOrThrow (absl::StatusOr<T>& status) {
213
- MaybeThrow (status.status ());
222
+ OkOrThrow (status.status ());
214
223
return status.value ();
215
224
}
216
225
217
226
template <class T >
218
227
const T& GetValueOrThrow (const absl::StatusOr<T>& status) {
219
- MaybeThrow (status.status ());
228
+ OkOrThrow (status.status ());
220
229
return status.value ();
221
230
}
222
231
223
232
template <class T >
224
233
T GetValueOrThrow (absl::StatusOr<T>&& status) {
225
- MaybeThrow (status.status ());
234
+ OkOrThrow (status.status ());
226
235
return std::move (status).value ();
227
236
}
228
237
229
238
// `GetValueOrThrow` overload for `Status`.
230
239
void GetValueOrThrow (const absl::Status& status);
231
240
232
- // Checks that `status` is an ok status.
233
- //
234
- // Otherwise, it will create a new status instance with the given source
235
- // location information, and incorporate its message (alongside the
236
- // status propagation trace) to the crash report.
237
- void OkOrDie (const absl::Status& status, const char * file, const int32_t line,
238
- const char * function, std::string_view message = " " );
239
-
240
241
} // namespace torch_xla
241
242
242
243
#endif // XLA_TORCH_XLA_CSRC_STATUS_H_
0 commit comments