[Rprotobuf-commits] r610 - in pkg: . src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Dec 27 22:33:43 CET 2013
Author: murray
Date: 2013-12-27 22:33:42 +0100 (Fri, 27 Dec 2013)
New Revision: 610
Modified:
pkg/ChangeLog
pkg/src/mutators.cpp
Log:
Address a TODO by adding a much more helpful stop error that tells the
user which element of a list didn't have the correct message type and
what the expected message type was.
Remove BEGIN_RCPP/END_RCPP from this function and let the exception
percolate up to the callers which have use those macros.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2013-12-27 21:10:36 UTC (rev 609)
+++ pkg/ChangeLog 2013-12-27 21:33:42 UTC (rev 610)
@@ -5,6 +5,9 @@
try/catch block so we catch any exceptions generated by Rcpp::as
or other functions and forward it along to an R-language stop()
error instead of terminating our R instance.
+ * src/mutators.cpp (rprotobuf): Add more helpful error message
+ specifying which element of a list is of the wrong type, and what
+ the expected type is, when setting a list of messages.
* inst/unitTests/runit.messages.R (test.message): Add unit tests
for our handling of setting repeated message fields.
* src/wrapper_Message.cpp: Add const qualifier to
Modified: pkg/src/mutators.cpp
===================================================================
--- pkg/src/mutators.cpp 2013-12-27 21:10:36 UTC (rev 609)
+++ pkg/src/mutators.cpp 2013-12-27 21:33:42 UTC (rev 610)
@@ -359,9 +359,10 @@
/**
* check that the values are suitable for the field descriptor
+ *
+ * @throws Rcpp::exception on error (uncaught)
*/
void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){
- BEGIN_RCPP
if( TYPEOF( values ) != VECSXP ){
Rcpp::stop("expecting a list of messages");
}
@@ -370,11 +371,19 @@
int n = LENGTH(values) ;
for( int i=0; i<n; i++){
if( !isMessage( VECTOR_ELT(values, i), target ) ){
- /* TODO: include i, target type and actual type in the message */
- Rcpp::stop("incorrect type");
+ // TODO(mstokely): When we have C++11 CXX11, use
+ // std::to_string(i)
+ // {{{
+ std::string s;
+ std::stringstream out;
+ out << i;
+ s = out.str();
+ // }}}
+ string message = "List element " + s + " is not a message " +
+ "of the appropriate type ('" + target + "')";
+ Rcpp::stop(message.c_str());
}
}
- VOID_END_RCPP
}
/**
More information about the Rprotobuf-commits
mailing list