netdevice_client/
error.rs

1// Copyright 2021 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
5//! Definition of possible errors in this crate.
6
7/// Possible errors in the crate.
8#[derive(thiserror::Error, Debug)]
9#[allow(missing_docs)]
10pub enum Error {
11    #[error(transparent)]
12    Fidl(#[from] fidl::Error),
13    #[error("unknown RxFlags({0}) set by driver")]
14    RxFlags(u32),
15    #[error("unknown FrameType({0}) set by driver")]
16    FrameType(u8),
17    #[error("invalid config: {0}")]
18    Config(String),
19    #[error("too many descriptors are chained ({0}), at most 4 are allowed")]
20    LargeChain(usize),
21    #[error("index out of bound {0} > {1}")]
22    Index(usize, usize),
23    #[error("failed to pad buffer to {0}, capacity {1}")]
24    Pad(usize, usize),
25    #[error("cannot allocate a buffer to meet the device requirement")]
26    TxLength,
27    #[error("failed to open session {0}: {1}")]
28    Open(String, zx::Status),
29    #[error("failed to create VMO {0}: {1}")]
30    Vmo(&'static str, zx::Status),
31    #[error("failed to {0} fifo {1}: {2}")]
32    Fifo(&'static str, &'static str, zx::Status),
33    #[error("failed to get size of {0} VMO: {1}")]
34    VmoSize(&'static str, zx::Status),
35    #[error("failed to map {0} VMO: {1}")]
36    Map(&'static str, zx::Status),
37    #[error("failed to validate netdev::DeviceInfo")]
38    DeviceInfo(#[from] crate::session::DeviceInfoValidationError),
39    #[error("failed to validate netdev::PortStatus")]
40    PortStatus(#[from] crate::client::PortStatusValidationError),
41    #[error("failed to attach port {0:?}: {1}")]
42    Attach(crate::Port, zx::Status),
43    #[error("failed to detach port {0:?}: {1}")]
44    Detach(crate::Port, zx::Status),
45    #[error("invalid base port identifier {0}")]
46    InvalidPortId(u8),
47    #[error("buffer is too small: {size} < {offset} + {length}")]
48    TooSmall { size: usize, offset: usize, length: usize },
49    #[error("received an invalid lease")]
50    InvalidLease,
51}
52
53/// Common result type for methods in this crate.
54pub type Result<T> = std::result::Result<T, Error>;