diff --git a/.github/workflows/r.yml b/.github/workflows/r.yml index 4f706e3e5b1..9e645f9bf2e 100644 --- a/.github/workflows/r.yml +++ b/.github/workflows/r.yml @@ -92,7 +92,7 @@ jobs: ulimit -c unlimited # Setting a non-default and non-probable Marquesas French Polynesia time # it has both with a .45 offset and very very few people who live there. - archery docker run -e TZ=MART -e ARROW_R_FORCE_TESTS=${{ matrix.force-tests }} ubuntu-r + archery docker run -e TZ=MART -e ARROW_R_FORCE_TESTS=${{ matrix.force-tests }} -e ARROW_EXTRA_ERROR_CONTEXT=ON ubuntu-r - name: Dump install logs run: cat r/check/arrow.Rcheck/00install.out if: always() diff --git a/ci/scripts/r_test.sh b/ci/scripts/r_test.sh index 0328df2384b..c6ceca632e8 100755 --- a/ci/scripts/r_test.sh +++ b/ci/scripts/r_test.sh @@ -85,6 +85,9 @@ fi # Make sure we aren't writing to the home dir (CRAN _hates_ this but there is no official check) BEFORE=$(ls -alh ~/) +# Install dev duckdb +${R_BIN} -e 'install.packages("remotes"); remotes::install_github("duckdb/duckdb/tools/rpkg#4712", build = FALSE)' + SCRIPT="as_cran <- !identical(tolower(Sys.getenv('NOT_CRAN')), 'true') if (as_cran) { args <- '--as-cran' diff --git a/r/src/array.cpp b/r/src/array.cpp index 8ba0c569ea4..d2dc29ee942 100644 --- a/r/src/array.cpp +++ b/r/src/array.cpp @@ -51,22 +51,22 @@ const char* r6_class_name::get(const std::shared_ptr void arrow::r::validate_slice_offset(R_xlen_t offset, int64_t len) { if (offset == NA_INTEGER) { - cpp11::stop("Slice 'offset' cannot be NA"); + arrow::arrow_stop("Slice 'offset' cannot be NA"); } if (offset < 0) { - cpp11::stop("Slice 'offset' cannot be negative"); + arrow::arrow_stop("Slice 'offset' cannot be negative"); } if (offset > len) { - cpp11::stop("Slice 'offset' greater than array length"); + arrow::arrow_stop("Slice 'offset' greater than array length"); } } void arrow::r::validate_slice_length(R_xlen_t length, int64_t available) { if (length == NA_INTEGER) { - cpp11::stop("Slice 'length' cannot be NA"); + arrow::arrow_stop("Slice 'length' cannot be NA"); } if (length < 0) { - cpp11::stop("Slice 'length' cannot be negative"); + arrow::arrow_stop("Slice 'length' cannot be negative"); } if (length > available) { cpp11::warning("Slice 'length' greater than available length"); @@ -90,10 +90,10 @@ std::shared_ptr Array__Slice2(const std::shared_ptr& void arrow::r::validate_index(int i, int len) { if (i == NA_INTEGER) { - cpp11::stop("'i' cannot be NA"); + arrow::arrow_stop("'i' cannot be NA"); } if (i < 0 || i >= len) { - cpp11::stop("subscript out of bounds"); + arrow::arrow_stop("subscript out of bounds"); } } @@ -162,13 +162,13 @@ bool Array__RangeEquals(const std::shared_ptr& self, const std::shared_ptr& other, R_xlen_t start_idx, R_xlen_t end_idx, R_xlen_t other_start_idx) { if (start_idx == NA_INTEGER) { - cpp11::stop("'start_idx' cannot be NA"); + arrow::arrow_stop("'start_idx' cannot be NA"); } if (end_idx == NA_INTEGER) { - cpp11::stop("'end_idx' cannot be NA"); + arrow::arrow_stop("'end_idx' cannot be NA"); } if (other_start_idx == NA_INTEGER) { - cpp11::stop("'other_start_idx' cannot be NA"); + arrow::arrow_stop("'other_start_idx' cannot be NA"); } return self->RangeEquals(*other, start_idx, end_idx, other_start_idx); } diff --git a/r/src/array_to_vector.cpp b/r/src/array_to_vector.cpp index dccc29537ed..4c9803d4668 100644 --- a/r/src/array_to_vector.cpp +++ b/r/src/array_to_vector.cpp @@ -599,8 +599,8 @@ class Converter_Dictionary : public Converter { // TODO: also add int64, uint32, uint64 downcasts, if possible break; default: - cpp11::stop("Cannot convert Dictionary Array of type `%s` to R", - dict_type.ToString().c_str()); + arrow::arrow_stop("Cannot convert Dictionary Array of type `%s` to R", + dict_type.ToString().c_str()); } if (chunked_array->num_chunks() > 0) { @@ -1352,7 +1352,7 @@ std::shared_ptr Converter::Make( break; } - cpp11::stop("cannot handle Array of type <%s>", type->name().c_str()); + arrow::arrow_stop("cannot handle Array of type <%s>", type->name().c_str()); } std::shared_ptr to_chunks(const std::shared_ptr& array) { diff --git a/r/src/arrow_cpp11.h b/r/src/arrow_cpp11.h index 123875325c6..5fbacf4891d 100644 --- a/r/src/arrow_cpp11.h +++ b/r/src/arrow_cpp11.h @@ -52,6 +52,24 @@ #endif namespace arrow { + +class RException : public std::runtime_error { + public: + explicit RException(const char* msg) : std::runtime_error(msg) {} +}; + +__attribute__((noreturn)) static inline void arrow_stop(const char* fmt, ...) { + char message[8096]; + memset(message, 0, sizeof(message)); + + va_list args; + va_start(args, fmt); + vsnprintf(message, sizeof(message), fmt, args); + va_end(args); + + throw RException(message); +} + namespace r { template @@ -64,14 +82,14 @@ struct Pointer { // User passed a character representation of the pointer address SEXP char0 = STRING_ELT(x, 0); if (char0 == NA_STRING) { - cpp11::stop("Can't convert NA_character_ to pointer"); + arrow::arrow_stop("Can't convert NA_character_ to pointer"); } const char* input_chars = CHAR(char0); char* endptr; uint64_t ptr_value = strtoull(input_chars, &endptr, 0); if (endptr != (input_chars + strlen(input_chars))) { - cpp11::stop("Can't parse '%s' as a 64-bit integer address", input_chars); + arrow::arrow_stop("Can't parse '%s' as a 64-bit integer address", input_chars); } ptr_ = reinterpret_cast(static_cast(ptr_value)); @@ -90,7 +108,7 @@ struct Pointer { // User passed a double(1) of the static-casted pointer address. ptr_ = reinterpret_cast(static_cast(REAL(x)[0])); } else { - cpp11::stop("Can't convert input object to pointer"); + arrow::arrow_stop("Can't convert input object to pointer"); } } @@ -207,12 +225,14 @@ Pointer r6_to_pointer(SEXP self) { if (!Rf_inherits(self, "ArrowObject")) { std::string type_name = arrow::util::nameof< cpp11::decay_t::type>>(); - cpp11::stop("Invalid R object for %s, must be an ArrowObject", type_name.c_str()); + arrow::arrow_stop("Invalid R object for %s, must be an ArrowObject", + type_name.c_str()); } void* p = R_ExternalPtrAddr(Rf_findVarInFrame(self, arrow::r::symbols::xp)); if (p == nullptr) { SEXP klass = Rf_getAttrib(self, R_ClassSymbol); - cpp11::stop("Invalid <%s>, external pointer to null", CHAR(STRING_ELT(klass, 0))); + arrow::arrow_stop("Invalid <%s>, external pointer to null", + CHAR(STRING_ELT(klass, 0))); } return reinterpret_cast(p); } @@ -357,7 +377,7 @@ SEXP to_r6(const std::shared_ptr& ptr, const char* r6_class_name) { SEXP r6_class = Rf_install(r6_class_name); if (Rf_findVarInFrame3(arrow::r::ns::arrow, r6_class, FALSE) == R_UnboundValue) { - cpp11::stop("No arrow R6 class named '%s'", r6_class_name); + arrow::arrow_stop("No arrow R6 class named '%s'", r6_class_name); } // make call: $new() diff --git a/r/src/arrow_types.h b/r/src/arrow_types.h index d9fee37e7f1..07c94117756 100644 --- a/r/src/arrow_types.h +++ b/r/src/arrow_types.h @@ -92,22 +92,33 @@ class UnwindProtectDetail : public StatusDetail { virtual std::string ToString() const { return "R code execution error"; } }; -static inline Status StatusUnwindProtect(SEXP token) { - return Status::Invalid("R code execution error") +static inline Status StatusUnwindProtect(SEXP token, std::string message) { + return Status::Invalid("R code execution error (", message, ")") .WithDetail(std::make_shared(token)); } +class MoreUsefulUnwindException : public cpp11::unwind_exception { + public: + explicit MoreUsefulUnwindException(SEXP token, std::string message = "") + : cpp11::unwind_exception(token) {} + + const char* what() const noexcept { return message_.c_str(); } + + private: + std::string message_; +}; + static inline void StopIfNotOk(const Status& status) { if (!status.ok()) { auto detail = status.detail(); const UnwindProtectDetail* unwind_detail = dynamic_cast(detail.get()); if (unwind_detail) { - throw cpp11::unwind_exception(unwind_detail->token); + throw MoreUsefulUnwindException(unwind_detail->token); } else { // ARROW-13039: be careful not to interpret our error message as a %-format string std::string s = status.ToString(); - cpp11::stop("%s", s.c_str()); + throw RException(s.c_str()); } } } diff --git a/r/src/buffer.cpp b/r/src/buffer.cpp index 97f6db5535a..046b0aec1b2 100644 --- a/r/src/buffer.cpp +++ b/r/src/buffer.cpp @@ -52,7 +52,7 @@ std::shared_ptr r___RBuffer__initialize(SEXP x) { default: break; } - cpp11::stop("R object of type <%s> not supported", Rf_type2char(TYPEOF(x))); + arrow::arrow_stop("R object of type <%s> not supported", Rf_type2char(TYPEOF(x))); } // [[arrow::export]] diff --git a/r/src/chunkedarray.cpp b/r/src/chunkedarray.cpp index 36884bb531b..c8db9740308 100644 --- a/r/src/chunkedarray.cpp +++ b/r/src/chunkedarray.cpp @@ -110,7 +110,7 @@ std::shared_ptr ChunkedArray__from_list(cpp11::list chunks, std::shared_ptr type; if (type_inferred) { if (n == 0) { - cpp11::stop("type must be specified for empty list"); + arrow::arrow_stop("type must be specified for empty list"); } type = arrow::r::InferArrowType(VECTOR_ELT(chunks, 0)); } else { diff --git a/r/src/compute-exec.cpp b/r/src/compute-exec.cpp index f9183a3a103..fa48de7c50e 100644 --- a/r/src/compute-exec.cpp +++ b/r/src/compute-exec.cpp @@ -375,7 +375,7 @@ std::shared_ptr ExecNode_Join( } else if (type == 7) { join_type = compute::JoinType::FULL_OUTER; } else { - cpp11::stop("todo"); + arrow::arrow_stop("todo"); } return MakeExecNodeOrStop( diff --git a/r/src/compute.cpp b/r/src/compute.cpp index 1ed949e7295..4dac9dee4dd 100644 --- a/r/src/compute.cpp +++ b/r/src/compute.cpp @@ -98,7 +98,7 @@ arrow::Datum as_cpp(SEXP x) { // This assumes that R objects have already been converted to Arrow objects; // that seems right but should we do the wrapping here too/instead? - cpp11::stop("to_datum: Not implemented for type %s", Rf_type2char(TYPEOF(x))); + arrow::arrow_stop("to_datum: Not implemented for type %s", Rf_type2char(TYPEOF(x))); } } // namespace cpp11 @@ -123,7 +123,7 @@ SEXP from_datum(arrow::Datum datum) { break; } - cpp11::stop("from_datum: Not implemented for Datum %s", datum.ToString().c_str()); + arrow::arrow_stop("from_datum: Not implemented for Datum %s", datum.ToString().c_str()); } std::shared_ptr make_compute_options( @@ -632,7 +632,7 @@ arrow::Result ResolveScalarUDFOutputType( cpp11::sexp output_type_sexp = state->resolver_(input_types_sexp); if (!Rf_inherits(output_type_sexp, "DataType")) { - cpp11::stop( + arrow::arrow_stop( "Function specified as arrow_scalar_function() out_type argument must " "return a DataType"); } @@ -681,7 +681,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context, // Error for an Array result of the wrong type if (!result->type()->Equals(array->type())) { - return cpp11::stop( + return arrow::arrow_stop( "Expected return Array or Scalar with type '%s' from user-defined " "function but got Array with type '%s'", result->type()->ToString().c_str(), array->type()->ToString().c_str()); @@ -693,7 +693,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context, // handle a Scalar result of the wrong type if (!result->type()->Equals(scalar->type)) { - return cpp11::stop( + return arrow::arrow_stop( "Expected return Array or Scalar with type '%s' from user-defined " "function but got Scalar with type '%s'", result->type()->ToString().c_str(), scalar->type->ToString().c_str()); @@ -703,7 +703,7 @@ arrow::Status CallRScalarUDF(arrow::compute::KernelContext* context, arrow::MakeArrayFromScalar(*scalar, span.length, context->memory_pool())); result->value = std::move(array->data()); } else { - cpp11::stop("arrow_scalar_function must return an Array or Scalar"); + arrow::arrow_stop("arrow_scalar_function must return an Array or Scalar"); } }, "execute scalar user-defined function"); @@ -716,7 +716,7 @@ void RegisterScalarUDF(std::string name, cpp11::list func_sexp) { R_xlen_t n_kernels = in_type_r.size(); if (n_kernels == 0) { - cpp11::stop("Can't register user-defined function with zero kernels"); + arrow::arrow_stop("Can't register user-defined function with zero kernels"); } // Compute the Arity from the list of input kernels. We don't currently handle @@ -726,7 +726,7 @@ void RegisterScalarUDF(std::string name, cpp11::list func_sexp) { for (R_xlen_t i = 1; i < n_kernels; i++) { auto in_types = cpp11::as_cpp>(in_type_r[i]); if (in_types->num_fields() != n_args) { - cpp11::stop( + arrow::arrow_stop( "Kernels for user-defined function must accept the same number of arguments"); } } diff --git a/r/src/config.cpp b/r/src/config.cpp index 1d322205b5d..b8942f44712 100644 --- a/r/src/config.cpp +++ b/r/src/config.cpp @@ -37,7 +37,7 @@ std::vector runtime_info() { void set_timezone_database(cpp11::strings path) { auto paths = cpp11::as_cpp>(path); if (path.size() != 1) { - cpp11::stop("Must provide a single path to the timezone database."); + arrow::arrow_stop("Must provide a single path to the timezone database."); } arrow::GlobalOptions options; diff --git a/r/src/csv.cpp b/r/src/csv.cpp index 7ce55feb5fe..d745cad2afe 100644 --- a/r/src/csv.cpp +++ b/r/src/csv.cpp @@ -131,14 +131,14 @@ std::shared_ptr csv___ConvertOptions__initialize( timestamp_parsers.push_back( cpp11::as_cpp>(x)); } else { - cpp11::stop( + arrow::arrow_stop( "unsupported timestamp parser, must be a scalar string or a " " object"); } } } else { - cpp11::stop( + arrow::arrow_stop( "unsupported timestamp parser, must be character vector of strptime " "specifications, or a list of objects"); } diff --git a/r/src/dataset.cpp b/r/src/dataset.cpp index 713c0d3b237..756de02956f 100644 --- a/r/src/dataset.cpp +++ b/r/src/dataset.cpp @@ -342,7 +342,7 @@ ds::SegmentEncoding GetSegmentEncoding(const std::string& segment_encoding) { } else if (segment_encoding == "uri") { return ds::SegmentEncoding::Uri; } - cpp11::stop("invalid segment encoding: " + segment_encoding); + arrow::arrow_stop("invalid segment encoding: %s", segment_encoding.c_str()); return ds::SegmentEncoding::None; } diff --git a/r/src/datatype.cpp b/r/src/datatype.cpp index dc8d3b18926..a7bb06cc414 100644 --- a/r/src/datatype.cpp +++ b/r/src/datatype.cpp @@ -203,10 +203,10 @@ std::shared_ptr DayTimeInterval__initialize() { // [[arrow::export]] std::shared_ptr FixedSizeBinary__initialize(R_xlen_t byte_width) { if (byte_width == NA_INTEGER) { - cpp11::stop("'byte_width' cannot be NA"); + arrow::arrow_stop("'byte_width' cannot be NA"); } if (byte_width < 1) { - cpp11::stop("'byte_width' must be > 0"); + arrow::arrow_stop("'byte_width' must be > 0"); } return arrow::fixed_size_binary(byte_width); } @@ -245,7 +245,7 @@ std::shared_ptr list__(SEXP x) { } if (!Rf_inherits(x, "DataType")) { - cpp11::stop("incompatible"); + arrow::arrow_stop("incompatible"); } auto type = cpp11::as_cpp>(x); @@ -260,7 +260,7 @@ std::shared_ptr large_list__(SEXP x) { } if (!Rf_inherits(x, "DataType")) { - cpp11::stop("incompatible"); + arrow::arrow_stop("incompatible"); } auto type = cpp11::as_cpp>(x); @@ -275,7 +275,7 @@ std::shared_ptr fixed_size_list__(SEXP x, int list_size) { } if (!Rf_inherits(x, "DataType")) { - cpp11::stop("incompatible"); + arrow::arrow_stop("incompatible"); } auto type = cpp11::as_cpp>(x); @@ -292,9 +292,9 @@ std::shared_ptr map__(SEXP key, SEXP item, bool keys_sorted = f key_field = std::make_shared("key", key_type, /* nullable = */ false); } else if (Rf_inherits(key, "Field")) { key_field = cpp11::as_cpp>(key); - if (key_field->nullable()) cpp11::stop("key field cannot be nullable."); + if (key_field->nullable()) arrow::arrow_stop("key field cannot be nullable."); } else { - cpp11::stop("key must be a DataType or Field."); + arrow::arrow_stop("key must be a DataType or Field."); } if (Rf_inherits(item, "DataType")) { @@ -303,7 +303,7 @@ std::shared_ptr map__(SEXP key, SEXP item, bool keys_sorted = f } else if (Rf_inherits(item, "Field")) { item_field = cpp11::as_cpp>(item); } else { - cpp11::stop("item must be a DataType or Field."); + arrow::arrow_stop("item must be a DataType or Field."); } return std::make_shared(key_field, item_field); diff --git a/r/src/io.cpp b/r/src/io.cpp index 321b1b17feb..9e61b24cbcc 100644 --- a/r/src/io.cpp +++ b/r/src/io.cpp @@ -351,20 +351,20 @@ class RConnectionRandomAccessFile : public arrow::io::RandomAccessFile, // save the current position to seek back to it auto current_pos = Tell(); if (!current_pos.ok()) { - cpp11::stop("Tell() returned an error"); + arrow::arrow_stop("Tell() returned an error"); } int64_t initial_pos = current_pos.ValueUnsafe(); cpp11::package("base")["seek"](connection_sexp_, 0, "end"); current_pos = Tell(); if (!current_pos.ok()) { - cpp11::stop("Tell() returned an error"); + arrow::arrow_stop("Tell() returned an error"); } size_ = current_pos.ValueUnsafe(); auto status = Seek(initial_pos); if (!status.ok()) { - cpp11::stop("Seek() returned an error"); + arrow::arrow_stop("Seek() returned an error"); } } @@ -416,7 +416,8 @@ class RIconvWrapper { RIconvWrapper(std::string to, std::string from) : handle_(Riconv_open(to.c_str(), from.c_str())) { if (handle_ == ((void*)-1)) { - cpp11::stop("Can't convert encoding from '%s' to '%s'", from.c_str(), to.c_str()); + arrow::arrow_stop("Can't convert encoding from '%s' to '%s'", from.c_str(), + to.c_str()); } } diff --git a/r/src/r_to_arrow.cpp b/r/src/r_to_arrow.cpp index b37ae5df78a..a32bc432385 100644 --- a/r/src/r_to_arrow.cpp +++ b/r/src/r_to_arrow.cpp @@ -296,7 +296,7 @@ class AsArrowArrayConverter : public RConverter { arrays_.push_back(std::move(array)); return Status::OK(); } catch (cpp11::unwind_exception& e) { - return StatusUnwindProtect(e.token); + return StatusUnwindProtect(e.token, "AsArrowArray conversion error"); } } @@ -1244,7 +1244,7 @@ std::shared_ptr vec_to_arrow__reuse_memory(SEXP x) { return MakeSimpleArray(x); } - cpp11::stop("Unreachable: you might need to fix can_reuse_memory()"); + arrow::arrow_stop("Unreachable: you might need to fix can_reuse_memory()"); } std::shared_ptr vec_to_arrow_ChunkedArray( @@ -1424,8 +1424,8 @@ std::shared_ptr Table__from_dots(SEXP lst, SEXP schema_sxp, StopIfNotOk(arrow::r::AddMetadataFromDots(lst, num_fields, schema)); if (!infer_schema && schema->num_fields() != num_fields) { - cpp11::stop("incompatible. schema has %d fields, and %d columns are supplied", - schema->num_fields(), num_fields); + arrow::arrow_stop("incompatible. schema has %d fields, and %d columns are supplied", + schema->num_fields(), num_fields); } // table @@ -1435,8 +1435,8 @@ std::shared_ptr Table__from_dots(SEXP lst, SEXP schema_sxp, auto check_name = [&](int j, SEXP, cpp11::r_string name) { std::string cpp_name(name); if (schema->field(j)->name() != cpp_name) { - cpp11::stop("field at index %d has name '%s' != '%s'", j + 1, - schema->field(j)->name().c_str(), cpp_name.c_str()); + arrow::arrow_stop("field at index %d has name '%s' != '%s'", j + 1, + schema->field(j)->name().c_str(), cpp_name.c_str()); } }; arrow::r::TraverseDots(lst, num_fields, check_name); diff --git a/r/src/recordbatch.cpp b/r/src/recordbatch.cpp index aca3a74fd81..eac1e1c2f92 100644 --- a/r/src/recordbatch.cpp +++ b/r/src/recordbatch.cpp @@ -48,7 +48,8 @@ std::shared_ptr RecordBatch__RenameColumns( const std::vector& names) { int n = batch->num_columns(); if (names.size() != static_cast(n)) { - cpp11::stop("RecordBatch has %d columns but %d names were provided", n, names.size()); + arrow::arrow_stop("RecordBatch has %d columns but %d names were provided", n, + names.size()); } std::vector> fields(n); for (int i = 0; i < n; i++) { @@ -239,8 +240,8 @@ std::shared_ptr RecordBatch__from_arrays__known_schema( StopIfNotOk(arrow::r::count_fields(lst, &num_fields)); if (schema->num_fields() != num_fields) { - cpp11::stop("incompatible. schema has %d fields, and %d arrays are supplied", - schema->num_fields(), num_fields); + arrow::arrow_stop("incompatible. schema has %d fields, and %d arrays are supplied", + schema->num_fields(), num_fields); } // convert lst to a vector of arrow::Array @@ -248,8 +249,8 @@ std::shared_ptr RecordBatch__from_arrays__known_schema( auto fill_array = [&arrays, &schema](int j, SEXP x, std::string name) { if (schema->field(j)->name() != name) { - cpp11::stop("field at index %d has name '%s' != '%s'", j + 1, - schema->field(j)->name().c_str(), name.c_str()); + arrow::arrow_stop("field at index %d has name '%s' != '%s'", j + 1, + schema->field(j)->name().c_str(), name.c_str()); } arrays[j] = arrow::r::vec_to_arrow_Array(x, schema->field(j)->type(), false); }; diff --git a/r/src/recordbatchreader.cpp b/r/src/recordbatchreader.cpp index c571d282da1..a9c4586ddae 100644 --- a/r/src/recordbatchreader.cpp +++ b/r/src/recordbatchreader.cpp @@ -69,7 +69,7 @@ class RFunctionRecordBatchReader : public arrow::RecordBatchReader { if (result_sexp == R_NilValue) { return std::shared_ptr(nullptr); } else if (!Rf_inherits(result_sexp, "RecordBatch")) { - cpp11::stop("Expected fun() to return an arrow::RecordBatch"); + arrow::arrow_stop("Expected fun() to return an arrow::RecordBatch"); } return cpp11::as_cpp>(result_sexp); @@ -154,7 +154,7 @@ int ipc___RecordBatchFileReader__num_record_batches( std::shared_ptr ipc___RecordBatchFileReader__ReadRecordBatch( const std::shared_ptr& reader, int i) { if (i < 0 && i >= reader->num_record_batches()) { - cpp11::stop("Record batch index out of bounds"); + arrow::arrow_stop("Record batch index out of bounds"); } return ValueOrStop(reader->ReadRecordBatch(i)); } diff --git a/r/src/safe-call-into-r-impl.cpp b/r/src/safe-call-into-r-impl.cpp index 4eec3a85df8..34da882f495 100644 --- a/r/src/safe-call-into-r-impl.cpp +++ b/r/src/safe-call-into-r-impl.cpp @@ -96,6 +96,6 @@ std::string TestSafeCallIntoR(cpp11::function r_fun_that_returns_a_string, arrow::StopIfNotOk(result.status()); return result.ValueUnsafe(); } else { - cpp11::stop("Unknown `opt`"); + arrow::arrow_stop("Unknown `opt`"); } } diff --git a/r/src/safe-call-into-r.h b/r/src/safe-call-into-r.h index 08e8a8c11b6..e75434cc6c9 100644 --- a/r/src/safe-call-into-r.h +++ b/r/src/safe-call-into-r.h @@ -123,7 +123,7 @@ arrow::Future SafeCallIntoRAsync(std::function(void)> fun, return fun(); } catch (cpp11::unwind_exception& e) { // Here we save the token and set the main R thread to an error state - GetMainRThread().SetError(arrow::StatusUnwindProtect(e.token)); + GetMainRThread().SetError(arrow::StatusUnwindProtect(e.token, reason)); // We also return an error although this should not surface because // main_r_thread.ClearError() will get called before this value can be diff --git a/r/src/schema.cpp b/r/src/schema.cpp index 2bc58f0fa36..e9b45d4c036 100644 --- a/r/src/schema.cpp +++ b/r/src/schema.cpp @@ -41,7 +41,7 @@ int Schema__num_fields(const std::shared_ptr& s) { std::shared_ptr Schema__field(const std::shared_ptr& s, int i) { if (i >= s->num_fields() || i < 0) { - cpp11::stop("Invalid field index for schema."); + arrow::arrow_stop("Invalid field index for schema."); } return s->field(i); diff --git a/r/src/type_infer.cpp b/r/src/type_infer.cpp index 616be0467f9..6092ce41264 100644 --- a/r/src/type_infer.cpp +++ b/r/src/type_infer.cpp @@ -45,7 +45,7 @@ std::shared_ptr InferArrowTypeFromFactor(SEXP factor) { template std::shared_ptr InferArrowTypeFromVector(SEXP x) { - cpp11::stop("Unknown vector type: ", VectorType); + arrow::arrow_stop("Unknown vector type: ", VectorType); } template <> @@ -54,7 +54,7 @@ std::shared_ptr InferArrowTypeFromVector(SEXP x) { return cpp11::as_cpp>(x)->type(); } - cpp11::stop("Unrecognized vector instance for type ENVSXP"); + arrow::arrow_stop("Unrecognized vector instance for type ENVSXP"); } template <> @@ -146,7 +146,7 @@ std::shared_ptr InferArrowTypeFromVector(SEXP x) { SEXP byte_width = Rf_getAttrib(x, symbols::byte_width); if (Rf_isNull(byte_width) || TYPEOF(byte_width) != INTSXP || XLENGTH(byte_width) != 1) { - cpp11::stop("malformed arrow_fixed_size_binary object"); + arrow::arrow_stop("malformed arrow_fixed_size_binary object"); } return arrow::fixed_size_binary(INTEGER(byte_width)[0]); } @@ -162,7 +162,7 @@ std::shared_ptr InferArrowTypeFromVector(SEXP x) { SEXP ptype = Rf_getAttrib(x, symbols::ptype); if (Rf_isNull(ptype)) { if (XLENGTH(x) == 0) { - cpp11::stop( + arrow::arrow_stop( "Requires at least one element to infer the values' type of a list vector"); } @@ -199,13 +199,13 @@ std::shared_ptr InferArrowType(SEXP x) { case VECSXP: return InferArrowTypeFromVector(x); default: - cpp11::stop("Cannot infer type from vector"); + arrow::arrow_stop("Cannot infer type from vector"); } } else { cpp11::sexp type_result = cpp11::package("arrow")["infer_type"]( x, cpp11::named_arg("from_array_infer_type") = true); if (!Rf_inherits(type_result, "DataType")) { - cpp11::stop("type() did not return an object of type DataType"); + arrow::arrow_stop("type() did not return an object of type DataType"); } return cpp11::as_cpp>(type_result);