Noob question: Can an interface method return null?

Skip to first unread message

Jens Alfke

Jan 12, 2022, 6:05:42 PMJan 12
to Cap'n Proto
This seems like a dumb question, but I’ve been unable to find an answer. Does the RPC system support null values? In particular, if an RPC method returns an interface, is it able to return null?

Say Widget is an interface, and in another interface I’ve got a method
widgetNamed @1 (name: String) -> (widget: Widget);
Can this method return null? I’m beginning to suspect it can’t, because when it tries to I get an error "Pipeline call on a request that returned no capabilities or was already closed”. (The implementation is in C++; to return null it just abstains from calling context.getResults().setWidget().)

If it can’t, what is the idiomatic way to provide an optional return value? Do I return an exception, or do I create my own `Optional` type as a union?


Kenton Varda

Jan 12, 2022, 6:31:11 PMJan 12
to Jens Alfke, Cap'n Proto
Any pointer type, including interfaces, can be null.

I think the problem here, though, is that you're making a pipelined call on the widget before the `wigitNamed()` RPC call has actually completed, and then later on `widgetNamed()` is completing with a null result, and so the pipelined call fails. The error you are seeing is a little confusingly-worded but is in fact the error that would be expected in this scenario.

So yeah, you *are* returning null correctly, it's just that on the client side you're trying to make a call to the null capability before the client actually finds out that it is null.


You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages