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

Wrap errors in rpc.Conn.receive #540

Merged
merged 1 commit into from
Aug 7, 2023
Merged
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
27 changes: 14 additions & 13 deletions rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package rpc // import "capnproto.org/go/capnp/v3/rpc"
import (
"context"
"errors"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -206,10 +207,10 @@ type Options struct {
// Logger is used for logging by the RPC system. Each method logs
// messages at a different level, but otherwise has the same semantics:
//
// - Message is a human-readable description of the log event.
// - Args is a sequenece of key, value pairs, where the keys must be strings
// and the values may be any type.
// - The methods may not block for long periods of time.
// - Message is a human-readable description of the log event.
lthibault marked this conversation as resolved.
Show resolved Hide resolved
// - Args is a sequenece of key, value pairs, where the keys must be strings
// and the values may be any type.
// - The methods may not block for long periods of time.
//
// This interface is designed such that it is satisfied by *slog.Logger.
type Logger interface {
Expand Down Expand Up @@ -567,7 +568,7 @@ func (c *Conn) receive(ctx context.Context) func() error {
case inMsg := <-incoming:
// reader error?
if inMsg.err != nil {
return inMsg.err
return fmt.Errorf("reader: %w", inMsg.err)
}
in = inMsg.IncomingMessage

Expand All @@ -578,7 +579,7 @@ func (c *Conn) receive(ctx context.Context) func() error {
switch in.Message().Which() {
case rpccp.Message_Which_unimplemented:
if err := c.handleUnimplemented(in); err != nil {
return err
return fmt.Errorf("handle Unimplemented: %w", err)
}

case rpccp.Message_Which_abort:
Expand All @@ -587,37 +588,37 @@ func (c *Conn) receive(ctx context.Context) func() error {

case rpccp.Message_Which_bootstrap:
if err := c.handleBootstrap(in); err != nil {
return err
return fmt.Errorf("handle Bootstrap: %w", err)
}

case rpccp.Message_Which_call:
if err := c.handleCall(ctx, in); err != nil {
return err
return fmt.Errorf("handle Call: %w", err)
}

case rpccp.Message_Which_return:
if err := c.handleReturn(ctx, in); err != nil {
return err
return fmt.Errorf("handle Return: %w", err)
}

case rpccp.Message_Which_finish:
if err := c.handleFinish(ctx, in); err != nil {
return err
return fmt.Errorf("handle Finish: %w", err)
}

case rpccp.Message_Which_release:
if err := c.handleRelease(ctx, in); err != nil {
return err
return fmt.Errorf("handle Release: %w", err)
}

case rpccp.Message_Which_disembargo:
if err := c.handleDisembargo(ctx, in); err != nil {
return err
return fmt.Errorf("handle Disembargo: %w", err)
}

case rpccp.Message_Which_resolve:
if err := c.handleResolve(ctx, in); err != nil {
return err
return fmt.Errorf("handle Resolve: %w", err)
}

case rpccp.Message_Which_accept, rpccp.Message_Which_provide:
Expand Down