MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / ThrowError

Function ThrowError

oneflow/core/common/error.cpp:376–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376void ThrowError(const std::shared_ptr<StackedError>& error) {
377 std::string error_str;
378 fmt::format_to(std::back_inserter(error_str), "{}: {}\n",
379 fmt::styled("Error", fmt::emphasis::bold | fmt::fg(fmt::color::red)),
380 GetErrorString(error));
381 // Append foreign stack trace (e.g. Python stack trace) when it is available.
382 if (ForeignFrameThreadLocalGuard::Current().has_value()) {
383 auto frame = *CHECK_JUST(ForeignFrameThreadLocalGuard::Current());
384 if (!IsMainThread()) {
385 if (auto* stack_getter = Singleton<ForeignStackGetter>::Get()) {
386 fmt::format_to(std::back_inserter(error_str),
387 fmt::emphasis::bold | fmt::fg(fmt::color::dark_orange),
388 "Related Python stack trace:");
389 if (IsPythonStackGetterEnabledByDebugBuild()) {
390 fmt::format_to(
391 std::back_inserter(error_str),
392 " (You are seeing this stack trace because you compiled OneFlow with "
393 "CMAKE_BUILD_TYPE=Debug. If you want to see it even with other CMAKE_BUILD_TYPEs, "
394 "you can set ONEFLOW_DEBUG or ONEFLOW_PYTHON_STACK_GETTER to 1)");
395 }
396 fmt::format_to(std::back_inserter(error_str), "\n{}",
397 stack_getter->GetFormattedStack(frame));
398 } else {
399 fmt::format_to(
400 std::back_inserter(error_str),
401 "You can set {} or {} to 1 to get the Python stack of the error.",
402 fmt::styled("ONEFLOW_DEBUG", fmt::emphasis::bold | fmt::fg(fmt::color::dark_orange)),
403 fmt::styled("ONEFLOW_PYTHON_STACK_GETTER",
404 fmt::emphasis::bold | fmt::fg(fmt::color::dark_orange)));
405 }
406 }
407 }
408 *MutThreadLocalError() = error;
409 if ((*error)->has_runtime_error()) { throw RuntimeException(error_str); }
410 if ((*error)->has_type_error()) { throw TypeException(error_str); }
411 if ((*error)->has_index_error()) { throw IndexException(error_str); }
412 if ((*error)->has_unimplemented_error()) { throw NotImplementedException(error_str); }
413 throw Exception(GetStackedErrorString(error));
414}
415
416const std::shared_ptr<StackedError>& ThreadLocalError() { return *MutThreadLocalError(); }
417

Callers 7

GetOrThrowMethod · 0.85
GetPtrOrThrowMethod · 0.85
GetOrThrowMethod · 0.85
GetOrThrowMethod · 0.85
GetOrThrowMethod · 0.85
operator=Method · 0.85
castMethod · 0.85

Calls 12

GetErrorStringFunction · 0.85
IsMainThreadFunction · 0.85
GetFunction · 0.85
MutThreadLocalErrorFunction · 0.85
RuntimeExceptionClass · 0.85
TypeExceptionClass · 0.85
IndexExceptionClass · 0.85
ExceptionClass · 0.85
GetStackedErrorStringFunction · 0.85
has_valueMethod · 0.45

Tested by

no test coverage detected