| 97 | } |
| 98 | |
| 99 | static inline void StopIfNotOk(const Status& status) { |
| 100 | if (!status.ok()) { |
| 101 | auto detail = status.detail(); |
| 102 | const UnwindProtectDetail* unwind_detail = |
| 103 | dynamic_cast<const UnwindProtectDetail*>(detail.get()); |
| 104 | if (unwind_detail) { |
| 105 | throw cpp11::unwind_exception(unwind_detail->token); |
| 106 | } else { |
| 107 | // We need to translate this to "native" encoding for the error to be |
| 108 | // displayed properly using cpp11::stop() |
| 109 | std::string s = status.ToString(); |
| 110 | cpp11::strings s_utf8 = cpp11::as_sexp(s); |
| 111 | const char* s_native = cpp11::safe[Rf_translateChar](s_utf8[0]); |
| 112 | |
| 113 | // ARROW-13039: be careful not to interpret our error message as a %-format string |
| 114 | cpp11::stop("%s", s_native); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | template <typename R> |
| 120 | auto ValueOrStop(R&& result) -> decltype(std::forward<R>(result).ValueOrDie()) { |