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