Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error client: return the error via Brand() #215

Merged
merged 2 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ type errorClient struct {
// ErrorClient returns a Client that always returns error e.
// An ErrorClient does not need to be released: it is a sentinel like a
// nil Client.
//
// The returned client's State() method returns a State with its
// Brand.Value set to e.
func ErrorClient(e error) *Client {
if e == nil {
panic("ErrorClient(nil)")
Expand Down Expand Up @@ -870,7 +873,7 @@ func (ec errorClient) Recv(_ context.Context, r Recv) PipelineCaller {
}

func (ec errorClient) Brand() Brand {
return Brand{}
return Brand{Value: ec.e}
}

func (ec errorClient) Shutdown() {
Expand Down
13 changes: 12 additions & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,12 +1181,23 @@ func (c *Conn) isLocalClient(client *capnp.Client) bool {
if client == nil {
return false
}
if ic, ok := client.State().Brand.Value.(*importClient); ok {

bv := client.State().Brand.Value

if ic, ok := bv.(*importClient); ok {
// If the connections are different, we must be proxying
// it, so as far as this connection is concerned, it lives
// on our side.
return ic.c != c
}

if _, ok := bv.(error); ok {
// Returned by capnp.ErrorClient. No need to treat this as
// local; all methods will just return the error anyway,
// so violating E-order will have no effect on the results.
return false
}

// TODO: We should return false for results from pending remote calls
// as well. But that can wait until sendCap() actually emits
// CapDescriptors of type receiverAnswer, since until then it won't
Expand Down