[Rprotobuf-commits] r513 - in pkg: . inst/unitTests src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 22 08:33:48 CEST 2013
Author: murray
Date: 2013-08-22 08:33:45 +0200 (Thu, 22 Aug 2013)
New Revision: 513
Modified:
pkg/ChangeLog
pkg/inst/unitTests/runit.addressbook.R
pkg/src/wrapper_Descriptor.cpp
Log:
Add better error handling for readASCII of characters. People frequently
forget to call file() around their pathname to invoke the
readASCIIFromConnection() method so hopefully the better error message here
will make this error clearer. Also add a checkException() test to make sure
we alert the user rather than silently returning an empty proto as before.
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2013-08-22 06:19:11 UTC (rev 512)
+++ pkg/ChangeLog 2013-08-22 06:33:45 UTC (rev 513)
@@ -1,5 +1,9 @@
2013-08-21 Murray Stokely <murray at FreeBSD.org>
+ * inst/unitTests/runit.addressbook.R (test.ascii): Add more tests.
+ * src/wrapper_Descriptor.cpp (rprotobuf): Add better error
+ handling for readASCII of text strings rather than returning
+ an empty proto.
* R/extensions.R: Add checks to ensure that a valid extension
FieldDescriptor is passed to getExtension and setExtension.
* inst/unitTests/runit.int64.R (test.int64): Add a test
Modified: pkg/inst/unitTests/runit.addressbook.R
===================================================================
--- pkg/inst/unitTests/runit.addressbook.R 2013-08-22 06:19:11 UTC (rev 512)
+++ pkg/inst/unitTests/runit.addressbook.R 2013-08-22 06:33:45 UTC (rev 513)
@@ -62,4 +62,8 @@
out.file2 <- tempfile()
writeLines("jibberish", file(out.file2))
book6 <- checkException( readASCII( tutorial.AddressBook, file(out.file2)))
+
+ # Verify that we get an exception if we forget the file() and thus treat the
+ # path as a protobuf string.
+ checkException( readASCII( tutorial.AddressBook, out.file2))
}
Modified: pkg/src/wrapper_Descriptor.cpp
===================================================================
--- pkg/src/wrapper_Descriptor.cpp 2013-08-22 06:19:11 UTC (rev 512)
+++ pkg/src/wrapper_Descriptor.cpp 2013-08-22 06:33:45 UTC (rev 513)
@@ -166,8 +166,11 @@
RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){
GPB::Message* message = PROTOTYPE( desc ) ;
- GPB::TextFormat::ParseFromString( input, message ) ;
- return( S4_Message( message ) ) ;
+ if (GPB::TextFormat::ParseFromString( input, message ) ) {
+ return( S4_Message( message ) ) ;
+ } else {
+ throw std::range_error("Could not parse ASCII protocol buffer from text string.");
+ }
}
RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr<GPB::Descriptor> desc, int conn_id){
More information about the Rprotobuf-commits
mailing list