Skip to content

RPC exceptions don't work as expected #602

@homier

Description

@homier

It's really tricky to understand, how can I return a logic exception to a client. At the moment we've got the exc package that should help us return meaningful errors to clients by setting Type and Prefix to an exception, for instance let's create an instance of Failed type exception annotated with custom prefix, which I want my client to receive:

var ErrAccessKeySignatureMismatched = exc.Annotate("E_ACCESS_KEY_SIGNATURE_MISMATCHED", "signature mismatched", errors.New("omitted cause error"))

Then, in a server handler, I'd like to send that created exception to a client:

func (h *Handler) HandleSomething(ctx, call) error {
    ...
    if signatureMismatched {
        return ErrAccessKeySignatureMismatched
    }
    ...
    return nil
}

And I expect my go-capnp client to receive that error, and it indeed receives it:

resolver/resolver.capnp:Resolver.resolveTransferHandler: E_ACCESS_KEY_SIGNATURE_MISMATCHED: signature mismatched

But when I cast received err to an exception, prefix in the cast exception is empty, so I can't match it directly to the root cause without some string parsing. See the following example:

func UnmarshalError(err error) error {
	ce, ok := err.(*exc.Exception)
	if !ok {
		return err
	}

        // exists is false, because ce.Prefix == ""
	if err, exists := ErrorsByPrefix[ce.Prefix]; exists {
		return err.Unwrap()
	}

	return err
}

I might've been lost in terms of capnproto protocol errors handling and producing, but seems like clearly something is broken with exception prefixes. Or maybe I just didn't find how to properly parse exceptions :)

P.S. Regardless if this issue is a bug or not, I think we need to improve documentation for exceptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions