fidl_next_protocol/error.rs
1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use thiserror::Error;
6
7use fidl_next_codec::DecodeError;
8
9/// Errors that can be produced by FIDL clients and servers.
10#[derive(Error, Clone, Debug)]
11pub enum ProtocolError<E> {
12 /// The underlying transport encountered an error.
13 #[error("the underlying transport encountered an error: {0}")]
14 TransportError(E),
15
16 /// The underlying transport was stopped gracefully.
17 #[error("the transport was stopped gracefully")]
18 Stopped,
19
20 /// The underlying transport was closed by the peer.
21 #[error("the underlying transport was closed by the peer")]
22 PeerClosed,
23
24 /// The underlying transport was closed by the peer with an epitaph.
25 #[error("the underlying transport was closed by the peer with epitaph: {0}")]
26 PeerClosedWithEpitaph(i32),
27
28 /// The client or server received a message with an invalid protocol header.
29 #[error("received a message with an invalid message header: {0}")]
30 InvalidMessageHeader(DecodeError),
31
32 /// The client received an epitaph with an invalid body.
33 #[error("received an epitaph with an invalid body")]
34 InvalidEpitaphBody(DecodeError),
35
36 /// The client received a response for a two-way message which it did not send.
37 #[error("received a response which did not correspond to a pending request: txid {txid}")]
38 UnrequestedResponse {
39 /// The transaction ID which there is no pending response for.
40 txid: u32,
41 },
42
43 /// The client received a response with the wrong ordinal for the two-way message.
44 #[error(
45 "received a response with the wrong ordinal for the two-way message; expected ordinal \
46 {expected}, but got ordinal {actual}"
47 )]
48 InvalidResponseOrdinal {
49 /// The expected ordinal of the response
50 expected: u64,
51 /// The actual ordinal of the response
52 actual: u64,
53 },
54}