Error reporting#

pw_rpc: Efficient, low-code-size RPC system for embedded devices

See pw_rpc2 error reporting for protobuf error patterns, which apply directly to pw_rpc (RPC1). This page explains how RPC1’s built-in status works and what we recommend for new and existing services.

How RPC1 status works#

Unlike pw_rpc2, RPC1 packets carry a uint32 status field (pw_rpc/internal/packet.proto). Because of this, clients handle two separate status surfaces:

  • RPC-layer status: Transport, channel, decode, or timeout failures reported by the RPC framework.

  • User (server) status: The pw::Status code returned by a C++ server method when it completes the call.

Two wire behaviors affect how you design RPC1 services:

  • Status codes only: The wire format has no error message string. Even when pw_status messages (PW_STATUS_MSG) are enabled on the server, pw_rpc only sends status.code() and drops the message.

  • Unary vs. streaming payloads: Unary and client-streaming final responses deliver both the status code and the response protobuf, even when the status is non-OK. Server-streaming and bidirectional-streaming final responses carry only the status code and no payload (see Wire protocol).

Put application errors in response messages#

For new RPC1 services, put application errors in the response protobuf (following pw_rpc2 error reporting). Have the server return pw::OkStatus() whenever it handled the request normally, rather than returning domain errors in RPC1’s user status.

Having two status channels caused subtle client bugs and rigid error contracts, which is why pw_rpc2 removed user status. Encoding errors in response messages gives you:

  • Simpler client code: Callers handle RPC-layer failures in one place instead of checking two separate status channels.

  • Uniform unary and streaming behavior: The same pattern works for unary calls, terminal stream errors, and long-lived streams where a single failed request should not end the stream.

  • Richer error details: Protobuf responses support custom enums, context fields, and tokenized or bounded messages that do not fit in a bare status code.

  • Clean migration to pw_rpc2: When serving RPC1 services through the pw_rpc2 adapter, non-OK server statuses discard the response payload and cancel the call by default. Opting out requires DeliverNonOkResponses (see Non-OK status codes and response payloads).

Working with existing RPC1 error statuses#

If you maintain existing RPC1 services that return non-OK server statuses:

  • Handle both client status surfaces: Handle RPC-layer errors separately from non-OK server statuses in your client.

  • Read payloads on non-OK unary responses: For unary and client-streaming RPCs, clients still receive the response protobuf alongside a non-OK server status, so error details in the payload remain accessible.

  • Reserve non-OK stream Finish() for rejection or aborts: For server-streaming and bidirectional-streaming RPCs, only pass a non-OK status to Finish() when rejecting or aborting the stream itself (for example, ALREADY_EXISTS, RESOURCE_EXHAUSTED, or UNAVAILABLE when a stream cannot be opened). Write a stream message for structured or per-request errors before finishing, or keep the stream open.