capnp-ruby
capnp-ruby copied to clipboard
Unhandled exceptions causing Ruby aborts
It seems important for the extension to catch and wrap any C++ exceptions so that they don't abort the interpreter. The first one I noticed was passing an empty string to make_from_bytes
:
require "capn_proto"
File.open("t.capnp", "w"){|f| f.write(DATA.read)}
module T
extend CapnProto::SchemaLoader
load_schema "t.capnp"
end
begin
T::Message.make_from_bytes("")
rescue Exception => e
puts "Never gonna get you here..."
end
__END__
@0xcc1a7e7464ae3256;
struct Message {
type @0 :Int8;
}
Producing:
libc++abi.dylib: terminating with uncaught exception of type kj::ExceptionImpl: src/capnp/message.c++:57: requirement not met: expected segment != nullptr && segment->containsInterval(segment->getStartPtr(), segment->getStartPtr() + 1); Message did not contain a root pointer.
stack: 0x1068a3c92 0x1068a73cd 0x1068457e6 0x106844462 0x10677c69b 0x10677c552 0x106521ebb 0x1065217f4 0x10650aac3 0x1065185a1 0x106519428 0x1063e26a4 0x1063e25ce 0x10639d01f 0x7fff8a2625fd
Abort trap: 6
There are others:
require "capn_proto"
File.open("t.capnp", "w"){|f| f.write(DATA.read)}
module T
extend CapnProto::SchemaLoader
load_schema "t.capnp"
end
__END__
@0x0;
struct Message {
type @0 :Int8;
}
libc++abi.dylib: terminating with uncaught exception of type kj::ExceptionImpl: t.capnp:0: bug in code: Invalid ID. Please generate a new one with 'capnpc -i'.
stack: 0x100b01dcf 0x100a2a19d 0x100a2a41c 0x100a07401 0x1009fdf30 0x100a0ca09 0x1009fc76d 0x1009fbbe1 0x100a2a6b7 0x100a22a3a 0x100a25149 0x100a23ef4 0x100a243bb 0x100a2803c 0x100a27fa0 0x1009dbd1d
Abort trap: 6
Even a generic exception would be preferable to aborting the interpreter; so long as there's the possibility of an interpreter abort the library's unusable in production code.
Of course, the library itself could handle more cases before passing off to C++, but I'm less concerned about that. Right now I have a unit test that aborts half-way through; a generically wrapped error would be much preferable since all my tests would still run.
@ntalbott Hey, thanks for your interest in the library. Unfortunately, I've been incredibly swamped and haven't had a chance to complete things; as a work-in-progress, it's still very much broken.
I'll hopefully have some more time within the next couple weeks to bang out a first stable version. Feel free to drop back in and pester me to get it done :).
@cstrahan Pester pester! I'm not quite adept with C extensions, but I'm working on improving the ruby objects to make them a bit more user-friendly.
I'm so glad you went with wrapping the C++ library. I really want to use this library to demonstrate capnproto to my team (mostly all rubyists), and implement some fun tools for us to build things with.
@Spaceghost Thanks :). I'll set aside some time this weekend to work on this.