Skip to main content

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
9use crate::FrameworkError;
10
11/// Errors that can be produced by FIDL clients and servers.
12#[derive(Error, Clone, Debug)]
13pub enum ProtocolError<E> {
14    /// The underlying transport encountered an error.
15    #[error("the underlying transport encountered an error: {0}")]
16    TransportError(E),
17
18    /// The underlying transport was stopped gracefully.
19    #[error("the transport was stopped gracefully")]
20    Stopped,
21
22    /// The underlying transport was closed by the peer.
23    #[error("the underlying transport was closed by the peer")]
24    PeerClosed,
25
26    /// The underlying transport was closed by the peer with an epitaph.
27    #[error("the underlying transport was closed by the peer with epitaph: {0}")]
28    PeerClosedWithEpitaph(i32),
29
30    /// The client or server received a message with an invalid protocol header.
31    #[error("received a message with an invalid message header: {0}")]
32    InvalidMessageHeader(DecodeError),
33
34    /// The client received an epitaph with an invalid body.
35    #[error("received an epitaph with an invalid body")]
36    InvalidEpitaphBody(DecodeError),
37
38    /// The client received a response for a two-way message which it did not send.
39    #[error("received a response which did not correspond to a pending request: txid {txid}")]
40    UnrequestedResponse {
41        /// The transaction ID which there is no pending response for.
42        txid: u32,
43    },
44
45    /// The client received a response with the wrong ordinal for the two-way message.
46    #[error(
47        "received a response with the wrong ordinal for the two-way message; expected ordinal \
48        {expected}, but got ordinal {actual}"
49    )]
50    InvalidResponseOrdinal {
51        /// The expected ordinal of the response
52        expected: u64,
53        /// The actual ordinal of the response
54        actual: u64,
55    },
56
57    /// The client or server received a message with an unknown ordinal, and the
58    /// strictness of the method or openness of the protocol does not allow for
59    /// unknown ordinals in that situation.
60    #[error("received a message with an unknown ordinal: {0}")]
61    UnknownOrdinal(u64),
62
63    /// The client or server failed to decode a message as the type indicated
64    /// by the ordinal.
65    #[error("failed to decode a message with ordinal {ordinal}: {error}")]
66    InvalidMessage {
67        /// The ordinal of the message that failed to decode.
68        ordinal: u64,
69        /// The error encountered while attempting to decode the message.
70        error: DecodeError,
71    },
72
73    /// The server responded to a flexible method with an invalid value.
74    #[error("invalid flexible response")]
75    InvalidFlexibleResponse,
76
77    /// The server responded to a flexible method with an unknown framework
78    /// error.
79    #[error("unknown framework error")]
80    UnknownFrameworkError {
81        /// The ordinal of the unknown framework error.
82        ordinal: i32,
83    },
84
85    /// The server responded to a flexible method with a framework error.
86    #[error("framework error: {0}")]
87    FrameworkError(#[from] FrameworkError),
88}