fidl_next_bind/
error.rs

1// Copyright 2025 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, EncodeError};
8use fidl_next_protocol::ProtocolError;
9
10/// Error returned by TryFrom on a strict enum if none of the members match the supplied value.
11#[derive(Debug)]
12pub struct UnknownStrictEnumMemberError(i128);
13
14impl UnknownStrictEnumMemberError {
15    /// Create a new error given an unknown value.
16    pub fn new(unknown_value: i128) -> Self {
17        Self(unknown_value)
18    }
19}
20
21impl core::fmt::Display for UnknownStrictEnumMemberError {
22    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23        write!(f, "Strict enum doesn't have a member with value: {}", self.0)
24    }
25}
26
27impl core::error::Error for UnknownStrictEnumMemberError {}
28
29/// An encoding, decoding, or transport FIDL error.
30#[derive(Error, Clone, Debug)]
31pub enum Error<
32    #[cfg(feature = "fuchsia")] E = <zx::Channel as fidl_next_protocol::Transport>::Error,
33    #[cfg(not(feature = "fuchsia"))] E,
34> {
35    /// A FIDL encoding error.
36    #[error("encoding error: {0}")]
37    Encode(#[from] EncodeError),
38    /// A FIDL decoding error.
39    #[error("decoding error: {0}")]
40    Decode(#[from] DecodeError),
41    /// A FIDL protocol error.
42    #[error("protocol error: {0}")]
43    Protocol(#[from] ProtocolError<E>),
44}