@@ -90,18 +90,18 @@ void RelToAltrep::Initialize(DllInfo *dll) {
90
90
template <class T >
91
91
static T *GetFromExternalPtr (SEXP x) {
92
92
if (!x) {
93
- cpp11::stop (" GetFromExternalPtr: need a SEXP pointer" );
93
+ rapi_error_with_context (" GetFromExternalPtr" , " need a SEXP pointer" );
94
94
}
95
95
if (!ALTREP (x)) {
96
- cpp11::stop (" GetFromExternalPtr: not an ALTREP" );
96
+ rapi_error_with_context (" GetFromExternalPtr" , " not an ALTREP" );
97
97
}
98
98
auto ptr = R_altrep_data1 (x);
99
99
if (TYPEOF (ptr) != EXTPTRSXP) {
100
- cpp11::stop (" GetFromExternalPtr: data1 is not an external pointer" );
100
+ rapi_error_with_context (" GetFromExternalPtr" , " data1 is not an external pointer" );
101
101
}
102
102
auto wrapper = (T *)R_ExternalPtrAddr (ptr);
103
103
if (!wrapper) {
104
- cpp11::stop (" GetFromExternalPtr: This looks like it has been freed" );
104
+ rapi_error_with_context (" GetFromExternalPtr" , " This looks like it has been freed" );
105
105
}
106
106
return wrapper;
107
107
}
@@ -120,12 +120,12 @@ bool AltrepRelationWrapper::HasQueryResult() const {
120
120
121
121
MaterializedQueryResult *AltrepRelationWrapper::GetQueryResult () {
122
122
if (!mat_error.empty ()) {
123
- cpp11::stop ( mat_error);
123
+ rapi_error_with_context ( " GetQueryResult " , mat_error);
124
124
}
125
125
126
126
if (!mat_result) {
127
127
if (n_cells == 0 ) {
128
- cpp11::stop ( " Materialization is disabled, use collect() or as_tibble() to materialize." );
128
+ rapi_error_with_context ( " GetQueryResult " , " Materialization is disabled, use ` collect()` or ` as_tibble()` to materialize." );
129
129
}
130
130
131
131
auto materialize_callback = Rf_GetOption1 (RStrings::get ().materialize_callback_sym );
@@ -153,7 +153,7 @@ MaterializedQueryResult *AltrepRelationWrapper::GetQueryResult() {
153
153
Materialize ();
154
154
155
155
if (!mat_error.empty ()) {
156
- cpp11::stop ( mat_error);
156
+ rapi_error_with_context ( " GetQueryResult " , mat_error);
157
157
}
158
158
159
159
// FIXME: Use std::experimental::scope_exit
@@ -204,7 +204,7 @@ void AltrepRelationWrapper::Materialize() {
204
204
auto local_mat_res = (MaterializedQueryResult *)local_res.get ();
205
205
if (local_mat_res->RowCount () > max_rows) {
206
206
mat_error = duckdb_fmt::format (
207
- " Materialization would result in more than {} rows. Use collect() or as_tibble() to materialize." ,
207
+ " Materialization would result in more than {} rows. Use ` collect()` or ` as_tibble()` to materialize." ,
208
208
max_rows);
209
209
return ;
210
210
}
@@ -322,7 +322,7 @@ void *RelToAltrep::DoRownamesDataptrGet(SEXP x) {
322
322
auto rownames_wrapper = AltrepRownamesWrapper::Get (x);
323
323
auto row_count = rownames_wrapper->rel ->GetQueryResult ()->RowCount ();
324
324
if (row_count > (idx_t )NumericLimits<int32_t >::Maximum ()) {
325
- cpp11::stop ( " Integer overflow for row.names attribute" );
325
+ rapi_error_with_context ( " altrep_rownames_integer_Elt " , " Integer overflow for row.names attribute" );
326
326
}
327
327
rownames_wrapper->rowlen_data [1 ] = -row_count;
328
328
return rownames_wrapper->rowlen_data ;
@@ -386,21 +386,21 @@ static R_altrep_class_t LogicalTypeToAltrepType(const LogicalType &type, const d
386
386
#endif
387
387
388
388
default :
389
- cpp11::stop ( " LogicalTypeToAltrepType: Column `%s ` has no type for altrep: %s " , name. c_str (),
390
- type. ToString (). c_str () );
389
+ std::string error_msg = " Column `" + name + " ` has no type for altrep: " + type. ToString ();
390
+ rapi_error_with_context ( " LogicalTypeToAltrepType " , error_msg );
391
391
}
392
392
}
393
393
394
394
size_t DoubleToSize (double d) {
395
395
if (d < 0 ) {
396
- cpp11::stop ( " rel_to_altrep: Negative size" );
396
+ rapi_error_with_context ( " DoubleToSize " , " Negative size" );
397
397
}
398
398
if (!std::isfinite (d)) {
399
399
// Return maximum size_t for Inf
400
400
return MAX_SIZE_T;
401
401
}
402
402
if (d >= (double )MAX_SIZE_T) {
403
- cpp11::stop ( " rel_to_altrep: Size overflow" );
403
+ rapi_error_with_context ( " DoubleToSize " , " Size overflow" );
404
404
}
405
405
return (size_t )d;
406
406
}
@@ -462,7 +462,7 @@ size_t DoubleToSize(double d) {
462
462
shared_ptr<AltrepRelationWrapper> rapi_rel_wrapper_from_altrep_df (SEXP df, bool strict, bool allow_materialized) {
463
463
if (!Rf_inherits (df, " data.frame" )) {
464
464
if (strict) {
465
- cpp11::stop (" rapi_rel_from_altrep_df: Not a data.frame" );
465
+ rapi_error_with_context (" rapi_rel_from_altrep_df" , " Not a data.frame" );
466
466
} else {
467
467
return nullptr ;
468
468
}
@@ -471,7 +471,7 @@ shared_ptr<AltrepRelationWrapper> rapi_rel_wrapper_from_altrep_df(SEXP df, bool
471
471
auto row_names = get_attrib (df, R_RowNamesSymbol);
472
472
if (row_names == R_NilValue || !ALTREP (row_names)) {
473
473
if (strict) {
474
- cpp11::stop (" rapi_rel_from_altrep_df: Not a 'special' data.frame, row names are not ALTREP" );
474
+ rapi_error_with_context (" rapi_rel_from_altrep_df" , " Not a 'special' data.frame, row names are not ALTREP" );
475
475
} else {
476
476
return nullptr ;
477
477
}
@@ -480,7 +480,7 @@ shared_ptr<AltrepRelationWrapper> rapi_rel_wrapper_from_altrep_df(SEXP df, bool
480
480
auto altrep_data = R_altrep_data1 (row_names);
481
481
if (TYPEOF (altrep_data) != EXTPTRSXP) {
482
482
if (strict) {
483
- cpp11::stop (" rapi_rel_from_altrep_df: Not our 'special' data.frame, data1 is not external pointer" );
483
+ rapi_error_with_context (" rapi_rel_from_altrep_df" , " Not our 'special' data.frame, data1 is not external pointer" );
484
484
} else {
485
485
return nullptr ;
486
486
}
@@ -489,7 +489,7 @@ shared_ptr<AltrepRelationWrapper> rapi_rel_wrapper_from_altrep_df(SEXP df, bool
489
489
auto tag = R_ExternalPtrTag (altrep_data);
490
490
if (tag != RStrings::get ().duckdb_row_names_sym ) {
491
491
if (strict) {
492
- cpp11::stop (" rapi_rel_from_altrep_df: Not our 'special' data.frame, tag missing" );
492
+ rapi_error_with_context (" rapi_rel_from_altrep_df" , " Not our 'special' data.frame, tag missing" );
493
493
} else {
494
494
return nullptr ;
495
495
}
0 commit comments